I was trying to make a spider shoot a projectile and have that projectile instantiate a web after a certain distance traveled. I know how to do impact markers and use onCollisionEnter2d but I am brain farting on how to do this in a top-down 2d game when the projectile does not hit a collider. Can anyone point me anything that might help?
I would imagine a Raycast in Physics2D would be useful to impacting things just ahead of you. I use them for high-speed bullets, bullets that would move so fast each frame they pass through targets by “stepping around” them in a given frame. By raycasting from where it is to where you are about to move it, you can find if you’re gonna hit anything.
EDIT: and to answer your actual question (my bad), from the Raycast you get back a RaycastHit2D, which is a structure that can tell you if you hit anything, as well as precisely the point of contact.
EDIT: reading Praetor’s reply below makes me think perhaps I misread your question OP. Be sure to chime in if nothing I’m saying makes sense!
Dead reckoning. Have the projectile check how far it has moved each frame (or each FixedUpdate if it’s a Rigidbody).
Once it has moved the minimum required distance, deploy the web.
Thanks for the replies. The Dead reckoning bit looks promising.