- Home /
Projectile motion arc 2d
I am making a tower defense game and have a code that makes my projectile go straight to the moving destination. I want to reproduce the same circular motion of the projectile toward in motion destination in the wizard's tower as in the video below. Any idea?
https://youtu.be/xtlUegGh19Y?t=330
My code:
transform.position = Vector2.MoveTowards (transform.position, target.transform.position, Time.deltaTime * Speed);
Vector3 dir = target.transform.position - transform.position;
float angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
Answer by dail · Jan 14, 2020 at 12:11 PM
Including the answer here for someone who in future needs the same thing as me. After some research and testing I got the desired effect based on the blog below:
https://catlikecoding.com/unity/tutorials/curves-and-splines/
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Start Coroutine after other has finished 4 Answers
2D Projectile Not Firing Based on Rotation 1 Answer
Reverse object position order 1 Answer