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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Cant seem to figure out how to Get my Character to face forward in my endless runner

Discussion in 'Getting Started' started by Alberth2, Jun 9, 2015.

  1. Alberth2

    Alberth2

    Joined:
    May 23, 2015
    Posts:
    6
    Hello,

    Im creating an endless runner game and so far its going great but when I insert my character hes running towards me and I have tried many things and cannot figure it out. Can someone please help. Thank you
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Rotate him 180 degrees about the Y axis.

    If that doesn't work, please post a more complete question, including how exactly you're rotating him, and what other scripts or animations are on him that might be controlling the rotation.
     
  3. Alberth2

    Alberth2

    Joined:
    May 23, 2015
    Posts:
    6
    Thanks for replying,
    So I just tries turning him 180 degrees, and he turns but when I move him left he goes right and vise versa. I have player control script on him that looks like this..

    usingUnityEngine;
    usingSystem.Collections;

    publicclassPlayerControl : MonoBehaviour {

    CharacterControllercontroller;
    boolisGrounded= false;
    publicfloatspeed = 6.0f;
    publicfloatjumpSpeed = 8.0f;
    publicfloatgravity = 20.0f;
    privateVector3moveDirection = Vector3.zero;

    //start
    voidStart () {
    controller = GetComponent<CharacterController>();

    }

    //Updateiscalledonceperframe
    voidUpdate (){
    if (controller.isGrounded) {
    GetComponent<Animation>().Play("run"); //play "run" animationifspacebarisnotpressed
    moveDirection = newVector3(Input.GetAxis("Horizontal"), 0, 0); //getkeyboardinputtomoveinthehorizontaldirection
    moveDirection = transform.TransformDirection(moveDirection); //applythisdirectiontothecharacter
    moveDirection *= speed; //increasethespeedofthemovementbythefactor "speed"

    if (Input.GetButton ("Jump")) { //play "Jump" animationifcharacterisgroundedandspacebarispressed
    GetComponent<Animation>().Stop("run");
    GetComponent<Animation>().Play("jump_pose");
    moveDirection.y = jumpSpeed; //addthejumpheighttothecharacter
    }
    if(controller.isGrounded) //settheflagisGroundedtotrueifcharacterisgrounded
    isGrounded = true;
    }

    moveDirection.y -= gravity * Time.deltaTime; //Applygravity
    controller.Move(moveDirection * Time.deltaTime); //Movethecontroller
    }

    //checkifthecharactercollectsthepowerupsorthesnags
    voidOnTriggerEnter(Colliderother)
    {
    if(other.gameObject.name == "Powerup(Clone)")
    {
    //dosomething
    }
    elseif(other.gameObject.name == "Obstacle(Clone)")
    {
    //dosomething
    }
    Destroy(other.gameObject); //destroythesnagorpowerupifcolllectedbytheplayer

    }
    }
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    OK, that's still the right thing to do. Now you just need to fix the backwards controls.

    Before I forget, please use code tags around your code so it's legible.

    As for the backwards controls, you could just throw a minus sign in front of Input.GetAxis("Horizontal"). Or you could flip that axis in the Input settings.

    But I suspect all this related confusion comes from the fact that you've got your guy advancing through the world the "wrong" way. Of course there isn't really any wrong way, but the following way will save you the most grief:
    • Define "forward" as down the +Z direction. (I suspect you're going towards -Z.)
    • Define "up" as in the +Y direction.
    • Now, "right" is in the +X direction and "left" is towards -X.
    That's just how the coordinate system works. Good models will already be modeled such that they face in the +Z direction, so that's probably how your character is already set up.

    Hmm, but maybe not. That's really the key. When you plop your model into a brand new scene, with its rotation set to 0, 0, 0, which way is he facing? +Z or -Z? Check this out very carefully, and report back... if it's -Z, is this something you (or your artist) can fix at the source?
     
  5. Alberth2

    Alberth2

    Joined:
    May 23, 2015
    Posts:
    6
    Still having issues but I found out the carachter asset i bought was designed poorly.