Collisions
By default every mesh in the scene is used for player collision detection.
Large scenes with 2 million triangles and thousands of objects are usually checked within 0-1ms. You can disable collisions for an object in the editor or with:
object.collider = false;
Player collision will prevent a play from moving through walls, obstacles and make the player fall when there is no floor. All player collisions are independent of physics, so if you need physics collisions, it's avised to crate a capsule/box/sphere collider and sync that with the player mesh.
Desktop movement uses an upright swept capsule rather than checking only the player's destination. The sweep blocks floors, walls, and ceilings at high travel speeds, then projects remaining movement along the contact surface for wall and slope sliding. Grounding uses a separate short downward probe so it does not snap the player to distant floors. When grounded movement is blocked by a stair riser, the controller tries a bounded 0.45-metre step-up path and accepts it only when the raised capsule is clear and finds walkable ground.
Static collider world-space vertex and triangle-bound caches stay resident while their combined size is at most 32 MB. Above that soft limit, an infrequent cleanup removes caches that have not been used by player movement for 2,000 movement frames. The cache registry uses weak references, so streamed objects can still be garbage-collected without waiting for the TTL.
Raycasting
Unia provides an accelerated raycaster which is typically 1000x faster than three's default one. By default each frame you can get the mouse, or VR controllers raycasted intersections using:
const currentIntersection = controls.intersections;
if you want to create a custom raycaster for something non standard:
const raycaster = new world.Raycaster();
const _direction = new U.Vector3()
// example make component look at main avatars position and raycast
_direction.copy(world.avatar.position)
_direction.sub(this.position).normalize()
raycaster.set(this.position, _direction)
const intersections = raycaster.closestIntersection({
objects: [],
frustumCull: false,
entireScene: true,
onlyColliders: false,
text: false,
});
Raycastable ordinary meshes and custom-shader meshes use their CPU triangle
geometry by default. To use the world-space axis-aligned bounding box instead,
set mesh.raycastBoundsOnly = true. The property is undefined by default and
only strict true selects the bounds-only path. A bounds-only ray that begins
inside the box reports distance 0.