I’ve been working on a 3d sidescroller shooter… using IK I can aim at a target in 3d space … projectiles fire from the muzzle of an equiped gun… and hit the 3dtarget… no problem…
But for the actual game play I want the projectiles to hit any target along it’s path… ( currently using ray tracing for collision of bullets with other colliders)
I’d like to have the projectiles hit any object … ignoring the depth to an extent…
So I make the projectile coplanar with the character… set the position.z of the bullet and 3dtarget.z to 0… which is the center point of all interactable objects…
This works fine ( although the visuals are off a bit)
Character colliders are hitboxes that follow animation. so if the current animation moves the depth of the hitbox enough the projectile misses even though visually from the side it looks like it hit.
With the way I have this set up it is the expected behaviour…
Anyone have other sutions to always hit? It’s almost like taking a dimension away from the positions …
One way is to stop using 3D colliders and go to 2D colliders, as those all exist at z == 0. This would require some work, especially if you use those colliders for other things.
Another way is to make the 3D colliders large enough in the Z direction that they always get hit, but that might have other issues.
Still another way is to iterate ALL the colliders that you CAN hit (via some central list of them) and cast a fresh ray that matches their Z at them going in the same X/Y direction and see if it hits.
To the point of the last choice, remember this about Raycasting, colliders, planes, Plane, etc: