I have a rocket I’m trying to launch. I have gravity on the rocket. I apply force as follows:
public class Launch : MonoBehaviour {
public float Power = 10;
// Use this for initialization
void Start () {
// Apply force to the newProjectile's Rigidbody to launch in the direction it's rotated at
float x = Mathf.Cos(Mathf.Deg2Rad * transform.rotation.eulerAngles.z);
float y = Mathf.Sin(Mathf.Deg2Rad * transform.rotation.eulerAngles.z);
GetComponent<Rigidbody2D>().AddForce(
new Vector2(x, y) * Power, ForceMode2D.Impulse);
}
// Update is called once per frame
void Update () {
}
}
This launches the rocket in the direction that I have its rotation setup.
This works; I see the object trace a trajectory I expect.
What doesn’t work properly is that the object does not rotate.
I am using a Capsule collider around the rocket, and the RigidBody2D does NOT have Freeze Rotation checked.
Here are the settings:
Here is the start of the rocket - you see it launching at around a 50 degree angle.
Here is the end of the trajectory - you see it hasn’t rotated at all, making it look very unnatural.
(Ignore the Rocket script attached to that prefab; it doesn’t affect RigidBody or physics or anything like that).