Quantcast
Channel: Questions in topic: "td"
Viewing all articles
Browse latest Browse all 11

How do I calculate the shooting Angle for a Tower?

0
0
I have a problem with my Bomb Tower in a TD 2D game. I can shoot the projectile with an given angle and a given force, but I want to give the script only the force, the tower position and the enemy position. I want to calculate the angle, so that the projectile of the tower is going at first above the enemy and then falling on the enemy. I already found a solution for this problem but it is in 3D.[3d Example of what I want in 2D][1]. My game is in 2D. If it helps, i am trying to replicate the Game "Kingdom Rush" and the bomb tower should look the same. thank you :) My Code yet: if (addForce) { float angle = ... ;//calculate the angle Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right; // calculate the direction with the angle rb.AddForce(dir * force); // add the direction and force to the rigidbody of the projectile addForce = false; // to add force only once at the beginning } What i want : ![(Sprites are from Kingdom Rush, if someone is wondering)][2] [1]: https://forum.unity.com/threads/how-to-calculate-force-needed-to-jump-towards-target-point.372288/ [2]: /storage/temp/149487-s.png

Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images