Raycasting in rows is a common practice.
- Is using the Physics 2D BoxCast function a good alternative to using multiple raycasts spread out (an example use being collision detection in a custom character controller script)?
- There is limited documentation on boxcasting. Would boxcasting be too intensive or more friendly to call each frame?
Answer
Box cast would probably be more performant since it's only checking 4 vertices but it'll definitely be more accurate, at least depending on what you want. Good idea!
Example use:
RaycastHit2D raycast = Physics2D.BoxCast (
//Starting point of box
Vector2.zero,
//Size of the box
new Vector2 (2,2),
//Angle of box,
0f,
//Direction to cast
Vector2.right,
//Distance to cast
5f
);
This BoxCasts starting from Vector2d.zero with a square of length 2 in the direction of (0,1), for a distance of 5. Conceptually, this is like dragging a 2x2 square from (0,0) to (0,5) and detecting any collisions along the way.
No comments:
Post a Comment