- Home /
Add a force at an angle
How do I add a force at specific angle to an object? Currently I am trying to do the following:
rigidbody2D.AddForce(new Vector2(1,Mathf.Cos(angle))*force);
where angle would represent the angle at which the force is added, so if i wanted a force straight up then angle would be 90. However this does not seem to work, and I would like to know what the correct way to accomplish this is. I am using C# and unity 2D
How are you getting the angle that you want to apply??
angle is just a public float which i am setting in the inspector
Answer by robertbu · Mar 04, 2014 at 05:20 AM
How about this:
Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
rigidbody2D.AddForce(dir*force);
The angle starts on the right and goes counter-clockwise.
I get the error
UnityEngine.$$anonymous$$athf' does not contain a definition for `AngleAxis'
Your answer
Follow this Question
Related Questions
Use Rigidbody2D's Drag to slow down flying character 1 Answer
Ball Rotating Help 0 Answers
Use force instead of transform.position 1 Answer
Adding force to rigidbody2d to slide 1 Answer
Separating direction from force w/ rigidbody.AddForce 1 Answer