I have an Orthographic game made in 3D. There is a mix of meshes and sprites. When Raycasting from the mouse, selection is nice and accurate.
However, I would like to know how to cast a ray between two points in the game world and ignore the Z axis entirely.
e.g.
Player — Floor — Wall — Target
The player is a sprite, as is the wall. The floor is a mesh and the target is another floor tile. If I cast a full 3D ray between the Target and the player, the wall might not be hit on the Z axis. How can I tell the ray to ignore the Z axis so all objects between the player and target will be hit, regardless of their position on the Z axis?
The Physics2D colliders idea seems good for the situation. Does this then mean there’s no way to do a 2D cast between both 3D and 2D colliders (since all it involves is ignoring one dimension)?
I ask because I think adding a 2D collider to the floor might be difficult as it is a 3D hexagon and there’s no specific collider for that (unless a 2D collider can shape itself around a 3D object on 2 specified axis?). The issue would be that since you select floor tiles the collision needs to be pretty accurate and the code does not store their real positions, just map positions. So I am relying on raycasting and Monobehaviour’s MouseEnter/Exit methods for selection
If your game has all logic in a 2D plane, and is seen from the side, 2D colliders is the way to go. If it’s got 3D elements, or is top-down, it’s not ideal.
Do you have a screenshot? That’d make it a lot easier to tell what you need.
I don’t know what you application is, but 2.5 d is done in adventure games all the time and they use 3d colliders. The reason being the character will scale if he/she moves backwards into the room. They are generally using a slightly overhead viewpoint. If it was going to be straight on side view and the character never moved backward into the scene, it wouldn’t matter.
Technically you can manage this with a normal BoxCast / BoxCastNonAlloc (in fact, most of the cast functions would work). Just set the X and Y extents to something really small, like .1f, and the Z extent to float.PositiveInfinity, be careful to set the orientation to a version of the “facing direction” with the Z euler angle zeroed out, and the rest should be identical to the raycast version. I have no idea what the performance difference is between something like that and a typical raycast though.