Reputation: 61
I am making a weapon in my 2D game that will shoot at a player-market target. Is there any way to have my bullet sprite follow the raycast2D that the weapon casts?
Upvotes: 0
Views: 265
Reputation: 1523
Since you have a ray (aka vector), on every frame of your animation, you can calculate the position of your sprite like so
spritePosition2d = rayStartPosition2d + rayNormal2d * bulletSpeed * timeElapsedFromShooting
where timeElapsedFromShoot
in seconds.
Feel free to give more details in the comments so I can update the answer to your requirements.
Let me know if this helps.
Upvotes: 0