Enemy hit in 3d types

This is just another trivial topic about handling logic of when should player and enemy health be reduced .

In 3d space I could think a solution :

  • most common use hitbox collider, ray cast ( if ray cast is hitting enemies hitbox your attack action will set -hp on enemy)

This is versatile as can be used for range, close attacks.
But on close distance for melee it will depends on size of hitbox, and the orientation of ray cast .

Which will open question, shall I just cast ray cast from middle of player body and changing length ? Or make some as extension of their weapon ?
What about in case of ranged weapon use screen with cross and cast ray cast from camera ?

So maybe there is need for multiple ray cast, or there is different more elegant options such just use of overlapping of colliders?( maybe fine for melee, but for ranged this could be more tricky as enemy could be behind the wall )

Anyway, how do you usually tackle it in 3d space ?

Area3D on melee weapons unless the hits aren’t registering. Then ShapeCast3D. Raycast3D for instant hit bullets, RigidBody3D for grenades that need to have arc and bounce, CharacterBody3D for physical bullets that need to ricochet.

1 Like