Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rotate player and changing its axis

Discussion in 'Scripting' started by Twainstar00, Sep 20, 2015.

  1. Twainstar00

    Twainstar00

    Joined:
    Mar 7, 2015
    Posts:
    46
    How can I rotate my player to the right (90 degrees) in a way that my "W" key (walk forward) would still apply with respect to the players rotation?

    What happens right now is when I rotate my player to the right, I need to press "D" to look like it is moving forward.
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    What code are you using to rotate your character & move it at the moment?
     
  3. Twainstar00

    Twainstar00

    Joined:
    Mar 7, 2015
    Posts:
    46
    Im using iTween.RotateTo and and iTween.MoveTo
     
  4. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    transform.forward is always the forward direction of the transform.

    So the easy way to do it is to say something like transform.position+=(transform.forward*Input.GetAxis("Horizontal"))*Time.deltaTime (If you're using Update)

    Though it's probably a better idea to make a new Vector3() and do all the movement calculations to that, then move the transform using that