windship

Hello,

I'm making a kind of gun-shooting game with spine characters.

I'm considering to make bullet's trail with Unity raycast but it seems not react with spine bounding boxes.

Any advices?
No tienes los permisos requeridos para ver los archivos adjuntos a este mensaje.
windship
  • Mensajes: 17

Harald

Unfortunately general Unity Physics rules apply here, since BoundingBoxFollower creates and updates a PolygonCollider2D collider, it will only interact with the 2D physics subsystem. Creating a 3D MeshCollider instead (an extruded polygon) is also not trivial, since it needs triangulation of the outline's vertices to work.

Easier solutions would be to either:
  • a) Manually create 3D BoxColliders and let them follow bones to interact with the 3D Physics raycast.
  • b) Since your Spine objects seem to be on the same Z plane: calculate the ray-intersection point of the ray and this plane, and then use Physics2D queries to determine if e.g. a circle lies within the 2D collider.
Avatar de Usuario
Harald

Harri
  • Mensajes: 1727

windship

I found an article and it solved my issue.

https://answers.unity.com/questions/1087239/get-2d-collider-with-3d-ray.html?childToView=1713394#answer-1713394

The magic keyword is "Physics2D.GetRayIntersection" and it make 3d raycast possible to interact with spine bounding box.
windship
  • Mensajes: 17

Harald

Oh, thanks very much for sharing, great find! I didn't know that this method was really casting a 3D ray through the cap-area of 2D colliders!
Avatar de Usuario
Harald

Harri
  • Mensajes: 1727

windship



Check how it works!
windship
  • Mensajes: 17

Harald

Very nice! :) Now add a hit animation! 8)
Avatar de Usuario
Harald

Harri
  • Mensajes: 1727


Volver a Unity