- Home /
Constant force on 2Drigidbodys
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.
Comment
Your answer
Follow this Question
Related Questions
2D metroid boost ball 0 Answers
Jumping with Rigidbody.AddForce not working? 1 Answer
Angle and Velocity in a Projectile 1 Answer