[SOLVED] Rotate Player according to key [W , A, S, D] --- Please Help
im working on a 3D top down type of game. i dont want camera to follow the player fixed scene level.
when i pressed the key[A & D] the player moving but he is not turning according to direction. im not into programming side please help me im struggling a lot with this....
i want to rotate my player....HELP
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed = 1f;
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.D)) {
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
}
if (Input.GetKey (KeyCode.A))
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
if (Input.GetKey (KeyCode.W))
transform.position += new Vector3 (0.0f, 0.0f, speed * Time.deltaTime);
if (Input.GetKey (KeyCode.S))
transform.position -= new Vector3 (0.0f, 0.0f, speed * Time.deltaTime);
}
}
Answer by Positive7 · Aug 25, 2015 at 10:42 PM
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float speed = 1f;
void Update () {
if (Input.GetKey (KeyCode.W)) {
transform.position += new Vector3 (0.0f, 0.0f, speed * Time.deltaTime);
transform.eulerAngles = new Vector3(0,0,0);
}
if (Input.GetKey (KeyCode.A)) {
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
transform.eulerAngles = new Vector3(0,-90,0);
}
if (Input.GetKey (KeyCode.S)) {
transform.position -= new Vector3 (0.0f, 0.0f, speed * Time.deltaTime);
transform.eulerAngles = new Vector3(0,180,0);
}
if (Input.GetKey (KeyCode.D)) {
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
transform.eulerAngles = new Vector3(0,90,0);
}
}
}
Dude..you are Awesome..Thank you soo much... :) im very happpy :)
Answer by SuperRaed · Aug 25, 2015 at 08:25 PM
what's a top down game? did you rotate the player and the background or just the camera? from what I know so far in unity, there are 2 types of axis a global axis that remains unchanged and is indepent of gameObjects ,and a local one which is dependent on the gameObjects orientation. so perhaps you changed the orientation of the player through either rotating the object itself or the background?