Question by
Ammar-Ali · Mar 31, 2016 at 02:59 PM ·
rotation2d gameacceleration
[Solved] Problem with achieving rotation relative to current acceleration value
Hi guys.
I have linked the rotation of a 2d object (an airplane) relative to its acceleration along the y axis.
The problem is the rotation is not based on current acceleration value.
Typically the acceleration ranges from -10 to 10. It feels like the rotation is based on a cumulative acceleration value rather than the current value. What I want is the rotation of plane change exactly in relation to its acceleration value.
Not sure if you guys understood what I mean. :p
Here is the script:
#pragma strict
//var previous: Vector3;
var velocity : float;
var acceleration : float;
var rb : Rigidbody2D;
function Start()
{
rb = GetComponent.<Rigidbody2D>();
acceleration = 0;
}
function Update()
{
acceleration = (rb.velocity.y - velocity)/Time.fixedDeltaTime;
velocity = rb.velocity.y;
transform.Rotate(0,0,-acceleration*Time.deltaTime*20);
// print (velocity);
//print (acceleration);
}
Any suggestions?
Update: Guys I figured out the solution. I removed *Time.deltaTime while defining the rotation function and now it works as I intended. Thanks
Comment