- Home /
Question by
thenachotech1113 · Jan 15, 2013 at 04:54 PM ·
velocityaccelerationairplane
object drifts when its using rigidbody.AddRelativeForce and i rotate it
hi, im trying to make a plane simulator and im using rigidbody.AddRelativeForce to accelerate it, but when it rotates it keeps going in that direction and it slowly starts pushing it to the direction it should, making it sort og like a drift. how do i stop that?
here is the code im using:
// acceleration
var planeSpeed : float;
var planeAcceleration : float = 7;
var planeAccelerationV : float;
var currentPlaneSpeed : float;
var speedSmoothDamp : float = 2;
var maxPlaneSpeed : float = 15;
//rotation
@HideInInspector
var xRotation : float;
@HideInInspector
var yRotation : float;
@HideInInspector
var zRotation : float;
var maxRotation : float = 7;
var rotSensibility : float = 7;
function Start () {
}
function Update () {
// acceleration
planeSpeed += Input.GetAxis("Mouse ScrollWheel") * planeAcceleration * Time.deltaTime * 100;
currentPlaneSpeed = Mathf.SmoothDamp(currentPlaneSpeed, planeSpeed, planeAccelerationV, speedSmoothDamp);
planeSpeed = Mathf.Clamp(planeSpeed, 0, maxPlaneSpeed);
currentPlaneSpeed = Mathf.Clamp(currentPlaneSpeed, 0, maxPlaneSpeed);
rigidbody.AddRelativeForce(0, 0, currentPlaneSpeed);
// rotation
xRotation = Input.GetAxis("Vertical") * rotSensibility * Time.deltaTime;
yRotation = Input.GetAxis("Horizontal") * rotSensibility * Time.deltaTime;
zRotation = Input.GetAxis("Roll") * rotSensibility * Time.deltaTime;
transform.Rotate(xRotation, yRotation, zRotation);
if (Input.GetAxis("Horizontal") == 0){
transform.Rotate(xRotation, 0, zRotation);
}
if (Input.GetAxis("Vertical") == 0){
transform.Rotate(0, yRotation, zRotation);
}
if (Input.GetAxis("Vertical") == 0){
transform.Rotate(xRotation, yRotation, 0);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613091002im_/https://answers.unity.com/themes/thub/images/avi.jpg)