- Home /
Question by
W1k3 · Nov 26, 2013 at 12:06 AM ·
rotationquaterniontimetime.deltatimeslerp
Quaternion.Slerp rotation speed increases over script life.
This is probably a basic slerp problem, but I'm using the arrow keys to switch between rotation points, and the speed in which it rotates gets faster and faster as the script goes on. If I leave the game running for about 20 seconds, my ship just snaps between rotations.
Any advice would be fantastic.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Transform ship;
public Transform top;
public Transform bottom;
public Transform left;
public Transform right;
public Transform straight;
Transform target;
public float rotatespeed = 5f;
public float translatespeed = 5f;
void Start () {
ship = transform;
rigidbody.AddForce(-1000, 0, 0);
}
void Update () {
//sets the rotations target based on what button is pressed
if (Input.GetAxis("Vertical") > 0) {
target = top;
}
else if (Input.GetAxis("Vertical") < -0) {
target = bottom;
}
else if (Input.GetAxis("Horizontal") > 0) {
target = right;
}
else if (Input.GetAxis("Horizontal") < -0) {
target = left;
}
else{
target = straight;
}
//ship 2D movement
ship.Translate(Vector3.forward * translatespeed * Input.GetAxis("Horizontal") * Time.deltaTime);
ship.Translate(Vector3.up * translatespeed * Input.GetAxis("Vertical") * Time.deltaTime);
//ship rotation
ship.rotation = Quaternion.Slerp(ship.rotation, target.rotation, Time.time * rotatespeed);
}
}
Comment
Best Answer
Answer by diegzumillo · Nov 26, 2013 at 12:09 AM
Use Time.deltaTime instead of Time.time :) (you might need to tweak your rotatespeed)
Your answer
Follow this Question
Related Questions
Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers
Use Lerp to rotate object 2 Answers
Basic AI Locked Axis 1 Answer
Rotating Rigidbodies 2 Answers