Hello!
I’m using that script to rotate my player in a 2.5D game:
using UnityEngine;
using System.Collections;
public class MoveLook : MonoBehaviour {
public float lookSpeed = 10;
private Vector3 curLoc;
private Vector3 prevLoc;
void Update ()
{
InputListen();
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.LookRotation(transform.position - prevLoc), Time.fixedDeltaTime * lookSpeed);
}
private void InputListen()
{
prevLoc = curLoc;
curLoc = transform.position;
if(Input.GetKey(KeyCode.A))
curLoc.x -= 1 * Time.fixedDeltaTime;
if(Input.GetKey(KeyCode.D))
curLoc.x += 1 * Time.fixedDeltaTime;
if(Input.GetKey(KeyCode.W))
curLoc.z += 1 * Time.fixedDeltaTime;
if(Input.GetKey(KeyCode.S))
curLoc.z -= 1 * Time.fixedDeltaTime;
transform.position = curLoc;
}
}
It works perfectly but when the player is in idle state it faces to Z axis, not to the current position.
My game is like a 2D Game but you can move to Z axis too. I have an static camera that’s only moves to x and y axis but alway is looking to Z axis.
Im trying to solve this but im stuck.
That's work. Now i'm trying to modify that script to a Joystick input like EasyJoystick. I think the easy way it's changing the "if(Input.GetKe..." for my own joysticks axis inputs, right?
– DiegusYou'll have two axes, one for horizontal and one for vertical. This means that you code will allow your character to rotate arbitrarily rather than just the four directions.
– robertbuYep, my character rotates well when input Axis its 1 or -1, if X and Y axis are active at same time it rotate arbitrarily. How to fix that?
– Diegus