Hello, I have the following script attached to a cube which allows it to be moved upwards. It translates and rotates according to left and right keyboard input, the only problem is that it rotates in world space, not it’s local space. How can I change this to make it rotate according to its own z-axis, not the worlds?
var momentum : float = 3;
//smooth : the lower the slower
var smooth;
function Update () {
var tiltAngle = -60.0;
var horiz = Input.GetAxis("Horizontal");
var target = Quaternion.Euler (0, 0, horiz*tiltAngle);
var zeroed = Quaternion.Euler (0, 0, 0);
//Increases forward momentum over time
momentum += Time.deltaTime*0.25;
//Left + right Translation and Upward Momentum
transform.Translate(horiz*0.25,Time.deltaTime*momentum, 0, Space.Self);
if (Input.GetButton("Horizontal")){
// Dampen towards the target rotation
smooth = 7.5;
transform.localRotation = Quaternion.Slerp(transform.localRotation, target,Time.deltaTime * smooth);
}
if(Input.anyKey == false){
smooth = 2;
transform.localRotation = Quaternion.Slerp(transform.localRotation, zeroed,Time.deltaTime * smooth);
}
}
I would really appreciate any help you can give me with this, I can’t seem to work it out myself.
Thanks