LookAt method is stuck on one axis, Why?
Hello fellow coders,
I am trying to make a top-Down game where my character is suppose to look where my mouse is, but for some reason he only rotates up and down, I will post the code down below, if you need any further information just ask.
Thanks for anyone, who takes the time to read this.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
public GameObject player; //The Playeable Dude
public GameObject target; //Curser = where the Dude wants to Look
public float speed = 30.0f; //How fast the Dude is
public float jumpForce = 5.0f; //How high the Dude can Jump
public Vector3 targetPosition; //Coordinats of the Cursor
void Update ()
{
targetPosition = Input.mousePosition;
Looking ();
PlayerMovement ();
//Input.mousePosition
Jump ();
}
void Looking ()
{
player.transform.LookAt(targetPosition);
}
void Jump()
{
if ( Input.GetKey("space") )
{
player.transform.Translate ( 0,jumpForce, 0);
}
}
void PlayerMovement ()
{
if (Input.GetKey("w"))
{
player.transform.Translate ( new Vector3 (0, 0, speed * Time.deltaTime));
}
if (Input.GetKey("s"))
{
player.transform.Translate ( new Vector3 (0, 0, -speed * Time.deltaTime));
}
if (Input.GetKey("a"))
{
player.transform.Translate ( new Vector3 (-speed * Time.deltaTime, 0, 0));
}
if (Input.GetKey("d"))
{
player.transform.Translate ( new Vector3 (speed * Time.deltaTime, 0, 0));
}
}
}
Comment