I’ve looked at several other questions and I’m probably just blind and missing something. Unity says there’s no errors in my code, I’m sure the Vector2 is correct, but it just doesn’t add the force.
public class BetterRocketControls : MonoBehaviour
{
public GameObject Rocket;
Vector2 rocketPosition;
float rocketAngleX;
float rocketAngleY;
float rocketAngleZ;
public const float pi = 3.1415926535897931f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
if (Input.GetAxis("Horizontal") < 0)
{
transform.Rotate(0.0f, 0.0f, 1.0f);
}
if (Input.GetAxis("Horizontal") > 0)
{
transform.Rotate(0.0f, 0.0f, -1.0f);
}
rocketPosition = transform.position;
rocketAngleZ = transform.rotation.eulerAngles.z;
// makes sure rocketAngleZ is between 0 and 360
if (rocketAngleZ > 360)
{
rocketAngleZ = rocketAngleZ - 360;
}
// converts rocketAngleZ from degrees to radians
rocketAngleZ = rocketAngleZ * pi/180;
Vector3 rocketAngle = new Vector3(rocketAngleX, rocketAngleY, rocketAngleZ);
Vector2 rocketForceDirection = new Vector2(Mathf.Cos(rocketAngleZ), Mathf.Sin(rocketAngleZ));
if (Input.GetAxis("Vertical") > 0)
{
Rocket.GetComponent<Rigidbody2D>().AddForce(rocketForceDirection);
Debug.Log(rocketPosition);
}
}
}