# Movement of the projectiles is weird.

Following a script attached to the ball projectile.

``````public class testScript : MonoBehaviour
{
GameObject shooter;
Rigidbody2D rb;

static Vector2 objectVelocity;

float xValue,yValue,angle;

void Start ()
{
shooter = GameObject.FindGameObjectWithTag ("shooter");
transform.eulerAngles = shooter.transform.eulerAngles;
rb = GetComponent<Rigidbody2D> ();
}

void Update ()
{
angle = transform.eulerAngles.z;
xValue = Mathf.Cos (angle);
yValue = Mathf.Sin (angle);
objectVelocity = new Vector2 (xValue, yValue);
rb.velocity = objectVelocity;
print (angle);
}

}
``````

But the testObject is not moving as they should be. I tried every possible solution but the problem is still same.

Weird, how?

In any case, Mathf.Cos and Sin want radians and youâ€™re giving them degrees.

1 Like

oops.

Iâ€™m not a maths student.

That level of math donâ€™t need a math degree though

I converted the degrees into Radians but the problem is still same.

What is the problem then? â€śweirdâ€ť doesnâ€™t really help me understand whatâ€™s wrong and what youâ€™re trying to achieve.

Let me show you.
Iâ€™m sending a screenshot.

How are you converting degrees to rad?

``````angle = transform.rotation.z * Mathf.Deg2Rad;
xValue = Mathf.Cos (angle);
yValue = Mathf.Sin (angle);
objectVelocity = new Vector3(xValue,yValue,0);
rb.velocity = objectVelocity;
print (angle);
``````

Are you using gravity?

Iâ€™m still not sure what youâ€™re trying to achieve exactly, there could be a number of things wrong with your script depending on what kind of motion you want.

There is a gameObject shooter (that hat) which shoot this ball. I am trying to shoot this ball in the direction of this shooter. I copied the rotation of the shooter to the ball. So it can go in the direction of this shooter.

And do you want a linear movement, or you want the ball to arc and eventually fall down due to gravity?

In any case, you shouldnâ€™t set the velocity every frame.

If you want a linear motion, you shouldnâ€™t use gravity (set the gravity scale on the rigidbody to 0 or set the gravity to 0 for the whole project)

No, it will be linear movement. Like in a bubble shooter. The ball will reflect when collided with walls. Iâ€™ve set the gravity scale to zero.