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
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
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.
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();
}
//Updateiscalledonceperframe
voidUpdate (){
if (controller.isGrounded) {
GetComponent().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().Stop(“run”);
GetComponent().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
}
}
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?
Still having issues but I found out the carachter asset i bought was designed poorly.