- Home /
Question by
unity_DAgdynkAR-IncQ · May 08 at 08:13 AM ·
objectunity 2dspeed
Putting a brakes on my spaceship
void Update()
{
float rotation = Input.GetAxis("Horizontal");
if (rotation != 0)
{
float rotationamount = RotateDegreesPerSecond *
Time.deltaTime;
if (rotation < 0)
{
rotationamount *= -1;
}
transform.Rotate(Vector3.forward, rotationamount);
// change thrust direction to match ship rotation
float rotationThrust = transform.eulerAngles.z *
Mathf.Deg2Rad;
ThrustDirection.x = Mathf.Cos(rotationThrust);
ThrustDirection.y = Mathf.Sin(rotationThrust);
}
}
private void FixedUpdate()
{
if (Input.GetAxis("Thrust") != 0)
{
rb.AddForce(ThrustDirection * ThrustForce *
Time.deltaTime, ForceMode2D.Force);
}
}
Comment