|
Hello, In the script below once the left/right buttons are pressed a motorcycle leans and then when the button is released it leans back to center. It works perfectly on the first couple of button presses but after that it jumps to the next transform instead of slowly moving. var toLeft : Transform;//bike lean left// var toRight : Transform;//bike lean right// var toCenter : Transform;//bike lean center// var speed = 0.01;//speed of lean// var returnCenter : boolean = false;//tells script it's ok to center bike// function Update () {
} Any ideas would be great!
(comments are locked)
|
|
Using Time.time will give you the time since the start of the game, which is why you are jumping after a bit. Replace Time.time with Time.deltaTime. This is almost correct, but still wrong. If you do this, you will always be going at some small amount * speed along the rotation from your current rotation to your target, meaning that with a large enough speed, it will quickly start any motion and then slow as it approaches the target without ever reaching it. You need a control variable to know how far you are leaned and you should rotate from one orientation to another, not your current orientation because that will change. Try:
If you want it to smooth at the ends, you could try Mathf.SmoothStep on lean. If you want it to smooth at the ends and at the start of your rotation, you would need to treat the motions separately and store your start rotation. Something like this should do it, handling when you have simultaneous key press/release events.
(comments are locked)
|
