- Home /
Need help to modify rotation script. (Quaternion)
Hi,just a simple script,who rotates target around x axis when "v" button is pressed. Anyway i cant figure out how to make that target rotates on y axis,i already tried to edit Vector3.up to Vector3.down,yes it rotates target on y axis,but when i again press "v" button it somehow changes to x axis. So all i want is to make that target only rotates on y axis by pressing "v" button and when pressing again it goes back to its position ( +180 and then -180 "y") Can someone PLEASE modify this script that it works like i want? Please guys. :) i Know its need to be done with Quaternion.Euler but HOW? PLEASE HELP!
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float smooth = 1f;
private Quaternion targetRotation;
void Update ()
{
if(Input.GetKeyDown(KeyCode.V))
targetRotation = Quaternion.LookRotation(-transform.forward, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, smooth * Time.deltaTime);
}
}
Comment
Best Answer
Answer by Sparrowfc · Nov 19, 2013 at 03:48 PM
maybe this's what you want:
void Update()
{
//choose any one you like
if(Input.GetKeyDown(KeyCode.V))
{
//use transform function
transform.RotateAround(transform.position, Vector3.up, 180 );
//use quaternion
transform.rotation *= Quaternion.AngleAxis(180, Vector3.up);
//use eulerAngles
transform.eulerAngles += new Vector3(0, 180, 0);
}
}