I have a 2D game with a plane. I want this plane to be affected by gravity and have a max speed. right now I'm just using AddForce() and it makes the sprite accelerate indefinitely.
I also want to move forward based on the rotation of the sprite. Here's what I have so far:
using UnityEngine;
using System.Collections;
public class PlaneScript : MonoBehaviour {
public float maxSpeed = 10f;
public Vector2 thrustForce = new Vector2(0, 100);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
//checks inputs
bool move = Input.GetButton ("Thrust");
float Yrotate = Input.GetAxis ("Horizontal");
//adjust thrust forward
if (move) {
rigidbody2D.AddForce( thrustForce );
}
//rotates plane based on A & D keys
rigidbody2D.transform.Rotate (0,0,(Yrotate- (2 * Yrotate))*maxSpeed);
}
}
Any help would be greatly appreciated.
↧