- Home /
Rotation with different speed for different axis
I just need to do a smooth rotation along two axis (x,z). The problem is that I need to have a different rotation speed for each axis. For example, now I have the same speed along every axis:
obj.eulerAngles = localRotationCamera.eulerAngles + targetRoll.eulerAngles + targetPitch.eulerAngles;
transform.localRotation = Quaternion.RotateTowards( transform.localRotation, obj , speedCameraMovementRoll);
I tried to separate each rotation, using speedCameraMovementPitch for the second one (separating obj too), but I've got naturally some strange behavior (maybe it doesn't know where to go, in the first or second RotateTowards). How can I solve my problem? Thanks in advance.
Answer by Quaker_SDR · Sep 01, 2014 at 11:58 AM
If i understand you right. this will b my soln. transform.localEulerAngles = new Vector3 (Mathf.Lerp (xvalue, x1value, xspeed), Mathf.Lerp (yvalue, y1value, yspeed), 0);
Answer by servival · Jun 27, 2015 at 04:01 PM
I hope this tank turret code helps you:
using UnityEngine;
using System.Collections;
public class AISmoothLookAT : MonoBehaviour {
public Transform target;
public Transform looker;
public Transform Xsmoothlooker;
public Transform Ysmoothlooker;
public float Xspeed = 2f;
public float Yspeed = 2f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
looker.LookAt (target);
float YRotation = looker.eulerAngles.y;
float XRotation = looker.eulerAngles.x;
Xsmoothlooker.rotation = Quaternion.Slerp(Xsmoothlooker.rotation , Quaternion.Euler(0 , YRotation, 0), Time.deltaTime * Xspeed);
Ysmoothlooker.rotation = Quaternion.Slerp(Ysmoothlooker.rotation , Quaternion.Euler(XRotation , YRotation, 0), Time.deltaTime * Yspeed);
}
}