Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GlossaryNovember 22, 20263 min read

What is a raycast?

Raycasts answer "what is in this direction, and how far?" Here is how they work and the jobs they do in almost every game: shooting, sight lines, cameras and footing.

Startbase Team
Editorial ink illustration of a pocket flashlight beam crossing a table to a toy soldier, the spot where the beam lands in ember orange

Key takeaways

  • A raycast traces a line from a point in a direction and returns the first thing it hits, with the hit point and distance.
  • It is the standard tool for hitscan weapons, enemy line of sight, ground checks, camera collision and tapping objects in 3D.
  • Use layers or filters so rays ignore the shooter and decorations, and cap the ray length.

Like a laser pointer that reports back, a raycast sends an invisible straight line from a starting point in a chosen direction and tells the game what it hit first, where, and how far away. Games fire dozens of them every frame to answer questions about the world.

Point a flashlight across a dark room and the beam stops on the first thing in its way: a chair, not the wall behind it. A raycast is that beam, minus the light, plus a note saying "chair, 2.3 meters".

What you give it and what you get back

You give a ray an origin, a direction, a maximum length, and usually a filter saying which kinds of objects count. It returns either nothing, or a hit with: the object, the exact point of contact, the distance, and the surface normal (which way the surface faces). The normal is what lets a bullet decal sit flat on a wall or a ricochet bounce at the right angle.

Jobs raycasts do in almost every game

  • Hitscan weapons. Lasers and most fast guns do not fly a bullet; they cast a ray from the barrel and damage whatever it hits that frame.
  • Line of sight. An enemy sees the player only if a ray from its eyes to the player hits the player first, not a wall. Stealth games run this several times a second per guard (line of sight and stealth).
  • Ground checks. A short ray (or two, from the left and right feet) straight down tells a character whether it is standing, and the normal tells how steep the slope is.
  • Camera collision. A third-person camera casts from the player to where the camera wants to be and moves in if a wall is in the way (third-person camera).
  • Tapping in 3D. A tap on the screen becomes a ray from the camera into the scene, which is how you select a unit or a tile.
  • Grapples and lasers. The grappling hook attaches where the ray lands.

Pitfalls

  1. 01Hitting yourself. A ray starting inside the shooter's own collider reports the shooter. Start it just outside, or filter the shooter out.
  2. 02Hitting decorations. Grass, particles and invisible triggers block shots unless rays use a layer mask that includes only solid things.
  3. 03Too many, too often. Ten guards casting at 60 Hz is 600 rays a second. Checking sight 5 to 10 times a second is usually enough and nobody notices.
  4. 04Thin rays, fat targets. A ray is infinitely thin and can slip between two crates. For bullets that should feel generous, use a sphere or shape cast, which sweeps a small ball along the line.

Raycasts when building with Startbase

The agent reaches for raycasts on its own for aiming, sight lines and ground checks. In 3D games, Rapier physics can do the casting when it is switched on. Your job is to describe the rule in plain words ("guards see 12 meters in a 90 degree cone, walls block sight, tall grass does not"), because that sentence turns directly into ray length, angle and filter.

Guards see the player within 12 meters inside a 90 degree cone. Check sight with a raycast 8 times a second from eye height; walls and closed doors block it, tall grass and glass do not. Add a debug toggle that draws each guard's sight rays, red when they hit the player.

Common confusions

  • Raycasting vs ray tracing. Ray tracing is a rendering technique that simulates light for graphics. Gameplay raycasts just query the world.
  • Raycasting vs old-school raycaster games. Early first-person games drew 3D-looking walls by casting one ray per screen column. Same idea, different job.
  • Raycast vs collision. Collisions notice touching; rays look ahead. See collision detection.

Frequently asked questions

What is a raycast used for in games?

Mostly aiming instant weapons, checking whether enemies can see the player, testing whether a character is on the ground, keeping cameras out of walls, and picking objects by tap or click.

Are raycasts expensive?

One is cheap. Hundreds every frame against complex scenes add up. Lower how often you check, cap ray length, and filter which objects are tested.

On this page

  • What you give it and what you get back
  • Jobs raycasts do in almost every game
  • Pitfalls
  • Raycasts when building with Startbase
  • Common confusions

Keep reading

More in Glossary
Editorial ink illustration of a hand-cranked music box drum plucking a metal comb, the crank handle in ember orange
GlossaryNovember 22, 2026

What is a game loop?

Every real-time game runs one repeating cycle: read input, update the world, draw it. Here is what that cycle looks like and why it decides how your game feels.

3 min read
Editorial ink illustration of a brass stopwatch beside a small wind-up toy car, the second hand in ember orange
GlossaryNovember 22, 2026

What is delta time?

Delta time is the number that keeps your game the same speed on every screen. Here is how to use it, where it breaks, and how to spot a game that forgot it.

3 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.