- Home /

# Finding angle of angular motion

Hi,

I couldn't figure it out with my inadeuqute physics knowledge. I am firing an arrow with a certain speed to a specific target. I know my position, target position, speed of the projectile and the angular rotation of the projectile. With those, I am trying to find the starting angle of the projectile to reach the destination. It is a simple projectile motion problem but the projectile motion equation is not interested of the angular rotation, it is calculation according to the gravity so this equation is not worknig for me:

```
Angle = (Mathf.Atan((Mathf.Pow(Vel, 2.0f) + Mathf.Sqrt(Mathf.Abs(Mathf.Pow(Vel, 4.0f) - Gravity * (Gravity * Mathf.Pow(xDist, 2.0f) + 2.0f * yDist * Mathf.Pow(Vel, 2.0f))))) / (Gravity * xDist))) * Mathf.Rad2Deg
```

Has anyone any idea to calculate the angle of a rotating arrow when the speed and the destination position is known? Thank you

I can help you out with this, but first I need some clarifications. When in Physics we say that a body has an angle of rotation, we mean rotation about one of its axis. In this case, the angle of rotation of an arrow would be an angle about its long axis, resulting in spinning the arrow. With this in mind, I don't understand what you mean by:

a. I know my ..., ... and the angular rotation of the angle b. Has anyone any idea to calculate the angle of a rotating arrow

I understand when you say "I am trying to find the starting angle of the projectile". So, "starting angle" is an obvious concept, but "angular rotation of the angle", and "angle of a rotating arrow", I don't understand. Maybe you are using different different words to always refer to starting angle.

Having said that, while the projectile motion equations are not interested in the starting angle, you can calculate this angle if you apply the equations separately, to the vertical and horizontal components of the resulting velocity. For this you need some simple trigonometry, and although it may sound complicated, it's quite simple.

Here is the theory:

Have a look at the article, and let me know what you need and I'll walk you through it.

Hi Pako, I am sorry, the angular rotation of the angle means the angular rotation of the projectile. I fixed it above. I was not quite clear maybe. The calculation I am trying to achieve is to find the start angle of the projectile to reach a target with a known destination, speed and also a known decreasing of the angle of the object. I am using transform.forward in my calculations and it makes all the formulas not working because I am applying the vector to the arrow in its local direction. So for example my arrow goes 5 m/s and every second it is rotating lower for one degree. If it starts with 50 degree, it is being 49 degree after a second. So do you have any idea if this type of calculation is applicable to the projectile motion formulas with a change?

Before getting into solving equations, I must clarify that "a known decreasing of the angle of the object" kind of complicates things (a lot). What you can do fairly easily, is find the starting angle for a known velocity of the projectile (arrow), in order to reach a known destination. During its flight, the projectile's velocity will have certain changing angles, which depend on the starting conditions (angle, velocity).

The starting angle in degrees can be found as follows:

```
startingAngle = (0.5 x Mathf.Asin((gravity x horizontal distance)/Mathf.Pow(startingSpeed,2))) * Mathf.Rad2Deg;
```

In plain English the starting angle is equal to one-half the arc-sine of the product of (gravity times horizontal distance), divided by the square of the speed. Unity's arc-sine function returns radians, so you have to multiply the result by a Radians-to-degrees conversion constant (Mathf.Rad2Deg) to get the angle in degrees.

To find the angle at different points in the trajectory is quite complex. If you absolutely need it, I'll have some searching to do. However, the easiest way, I think, is to interpolate the angle of the arrow during its flight between known angles. e.g you now know the starting angle. You also know that at maximum height (when vertical velocity = 0) the arrow will be horizontal. Also if the target is at the same height as the shooter, the angle when the arrow hits the target will be the same as the starting angle.

I love that link @Pako! nice one for that. cheers bud. Gruffy

**Answer** by Gruffy
·
Mar 23, 2014 at 04:08 PM

Hey bud. I think you could simplify your problem and use a rigidbody. If you take this script and add it to your camera or a parent gameobject of your camera. and add a prefab of your arrow to it in the inspector. MOST IMPORTANTLY, YOUR ARROW GAMEOBJECT SHOULD HAVE A RIGIDBODY COMPONENT ADDED TO IT. Sorry for shouting lol Gruffy Code below:

```
using UnityEngine;
using System.Collections;
public class Shooter : MonoBehaviour
{
GameObject currentCol;
//declare and init shooter vars
public Rigidbody bullet; //add a prefab(arrow) MAKE SURE THE ARROW HAS RIGIDBODY COMPONENT ATTACHED TO IT
public float power = 1500f; //forward power
// Update is called once per frame
void Update ()
{
if(Input.GetButtonUp("Fire1"))
{
//instantiate projectile - (overloads) what ?, where ?, a rotation ?
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
//vector to represent forward direction of the current transform
Vector3 fwd = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd * power);
//Physics.IgnoreCollision (transform.root.collider, bullet.collider, true);
//audio.PlayOneShot(bulletAudio);
}
}
}
```

Additional: Your "Fire1" is auto set to left mouse click btw. :) Gruffy

Hi,

I do not want to use Unity's physics system to have complete control of the system so that is out of the option. Pako, thanks for your help. I have gone so far learning projectile motion and going through all the trigonometry equations but still things are not going well.

That is so much better for me to submit all the code for better understanding.

```
using UnityEngine;
using System.Collections;
public class Projectile : MonoBehaviour
{
public float speed = 1.0f;
public float gravity = 1.0f;
bool moving = true;
float rAngle;
Transform Target;
public IEnumerator shootit(Transform curtarget)
{
Vector3 randompos = curtarget.position;
//Sending the values to the function for the angle calculation and rotating against the right angle
CalculateShot(randompos, speed, gravity);
while (moving)
{
//Applying velocity to the transform according to the local rotation
transform.position += -transform.forward * speed;
//Decreasing degree instead of using a gravity so it will behave like a natural gravitational rotation
transform.eulerAngles += new Vector3(gravity, 0, 0);
yield return null;
}
}
void OnTriggerEnter(Collider other)
{
moving = false;
}
void CalculateShot(Vector3 tPos , float pVel , float pGravity )
{
float xDist;
float yDist;
float hDist;
//Changing the turning degree to the format of natural gravity such as 9.81 so the gravity equation will work correct
pGravity = Mathf.Sin(pGravity) * pVel;
//Distance
hDist = Vector3.Distance(transform.position, tPos);
//Vertical distance
yDist = tPos.y - transform.position.y;
//Horizontal distance
xDist = Mathf.Sqrt(Mathf.Pow(hDist, 2) - Mathf.Pow(yDist, 2));
//Equation of projectile motion to find the angle
//The source that the formula is taken as Angle required to hit coordinate (x,y) : http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_required_to_hit_coordinate_.28x.2Cy.29
//The code improved from here : http://forum.unity3d.com/threads/208397-Projectile-motion-strange-behavior
rAngle = (Mathf.Atan((Mathf.Pow(pVel, 2.0f) - Mathf.Sqrt(Mathf.Abs(Mathf.Pow(pVel, 4.0f) - pGravity * (pGravity * Mathf.Pow(xDist, 2.0f) + 2.0f * yDist * Mathf.Pow(pVel, 2.0f)))) ) / (pGravity * xDist))) * Mathf.Rad2Deg;
//Applying angle
transform.localEulerAngles = new Vector3(rAngle, 180, 0);
}
}
```

The code based on the projectile motion code from here as the title Angle required to hit coordinate (x,y) : http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_required_to_hit_coordinate_.28x.2Cy.29

Also I am attaching the 200 kbproject for better understanding that is simple and show out of the box. I would appreciate anyone who is pointing me the problem: https://dl.dropboxusercontent.com/u/35804228/Arrows%20example.zip

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Simple projectile motion with wind 0 Answers

Projectile motion with angle and force in one direction 1 Answer

Rotating projectile 2 Answers

Projectiles, their speed, and collisions 1 Answer

shoot a cannon ball cannot run !! 0 Answers