How do I make an object face a direction instantly?
I've looked absolutely everywhere for a question that I'm sure has a really simple answer that no one has answered (online at least that I could find and I went through 7 pages of the google search). So I ask a simple question. How can I make an object face a direction, not rotate that direction, not face towards an object, just instantly turn and look that direction, for example turn and look 90 degrees. Because there is a way to make an object go to a location quickly and simply, so how do I do it with rotation?
transform.Rotate(0,90,0) not work? It changes the object's rotation instantly
of course transfrom.rotate is working, but what I want to do is when you press say the left arrow key, it will instantly turn to face left. But when you press the arrow key again (if it's already facing left) then it will not turn anymore.
Answer by SmomoGame · Oct 19, 2016 at 01:12 PM
After read your comment, I finally figure out what you want.
You can try Quaternion.LookRotation() , it generates a Quaternion with a Direction vector
exsample:
if you want press Left Arrow and player face the "Camera's Left", you can do below
void Update(){
if(Input.GetKeyDown(KeyCode.LeftArrow)){
transform.rotation = Quaternion.LookRotation(-Camera.main.transform.right) ;
}
}
Or you can change Camera.main.transform.right to a literal direction like new Vector3(-1,0,0)
I just tried that and whenever I pressed the key rather than turning it would disappear.
this is the script I put in:
using UnityEngine; using System.Collections;
public class $$anonymous$$ovementBikeBlue : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.D))
{
transform.rotation = Quaternion.LookRotation(Camera.main.transform.right);
}
}
}
But when I try the Vector3 version it gives me an error
Your answer
![](https://koobas.hobune.stream/wayback/20220612094935im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Teleporting problems 1 Answer
teleport point switch to new scene 0 Answers
Rotating object relative to player to orient it center of camera regardless of direction. 0 Answers
What is lerpSpeed? 0 Answers