Search Unity

Character not facing where it's suposed to!

Discussion in 'Getting Started' started by AdowTatep, May 28, 2015.

  1. AdowTatep

    AdowTatep

    Joined:
    Feb 5, 2015
    Posts:
    6
    I'm making a isometric prototype game and using unity chan on it, and i'm on the basics of learning. Her movement is using this code on update:

    Code (CSharp):
    1.         horizMove = Input.GetAxis("Horizontal");//Stores the horizontal move value in the variable
    2.         vertMove = Input.GetAxis("Vertical");//Stores the vertical move value in the variable
    3.  
    4.         Vector3 movement = new Vector3(horizMove, 0, vertMove);
    5.  
    6.         rigidB.AddForce(movement * moveSpeed / Time.deltaTime);
    7.  
    I want her to face right when pressed right, left when pressed left and so on and considering the camera but if i use this:

    Code (CSharp):
    1. if (horizMove > 0.1)//If you pressed Right
    2.         {
    3.             gameObject.transform.eulerAngles = new Vector3(0, mainCamera.transform.rotation.eulerAngles.y+90, 0);
    4.             rigidB.AddForce(gameObject.transform.forward);
    5.         }
    6.         else if (horizMove < 0)//If you pressed Left
    7.         {
    8.             gameObject.transform.eulerAngles = new Vector3(0, mainCamera.transform.rotation.eulerAngles.y -90, 0);
    9.         }
    10.  
    11.         else if (vertMove > 0.1)//If you pressed Up
    12.         {
    13.             gameObject.transform.eulerAngles = new Vector3(0, mainCamera.transform.rotation.eulerAngles.y, 0);
    14.  
    15.         }
    16.         else if (vertMove < 0)//If you pressed Down
    17.         {
    18.             gameObject.transform.eulerAngles = new Vector3(0, mainCamera.transform.rotation.eulerAngles.y-180, 0);
    19.         }
    She justs looks left, right up and down, not down+right, up+right etc, and it's not even smooth! I'm not goot at searching on google, i searched it and found tutorials that i could improve my movement script, but i don't know how to make it rotate :(
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    She can't look into two directions at once, because all your conditions are mutually exclusive.

    Secondly, it can't be smooth because you don't make it happen smoothly. You're setting a hard rotation that's not dependent on time, and that's it. If you want a smooth rotation, you have to rotate over time.