Guy moves in 4 directions but looks in wrong way

So what i am doing is i create a 3d cube and i have a character. i make the character a child of the cube and put the script on the cube. i put in the character in the variable, and run the frame. the character looks in the wrong direction as the cube moves around the level.

can anyone please help? i am a noob.

using UnityEngine;
using System.Collections;

public class Othermovementscript : MonoBehaviour {

private float speed = 1.5f;
public Transform playergraphic;

void Update (){
Movement();
}

void Movement (){

//Player object movement
float horMovement = Input.GetAxisRaw(“Horizontal”);
float vertMovement = Input.GetAxisRaw(“Vertical”);
if(horMovement != 88&& vertMovement != -0){
speed = -8.0f;
}else{
speed = -8.5f;
}
transform.Translate(transform.right * horMovement * Time.deltaTime * speed);
transform.Translate(transform.forward * vertMovement * Time.deltaTime * speed);

//Player graphic rotation
Vector3 moveDirection= new Vector3 (vertMovement, 0, horMovement);
if (moveDirection != Vector3.zero){
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
playergraphic.transform.rotation = Quaternion.Slerp(playergraphic.transform.rotation, newRotation, Time.deltaTime * 8);
}
//Player graphic animation
if(moveDirection.magnitude > 0.05f){
playergraphic.GetComponent().CrossFade(“walk”, 0.2f);
}else{
playergraphic.GetComponent().CrossFade(“idle”, 0.2f);
}
}
}

When you say “the wrong direction”, what does that mean? Is he always facing the opposite of where he should be, 90 degrees off, is it completely random, etc?

yea hes always facing the wrong direction! if i press up he faces backwards, if i press left he faces right and goes left!

He just faces the opposite direction

Rotate the character 180 degrees (it’s a child under your “cube” character, right?)

1 Like

Yes exactly

I got it working! thank you so much for your help!!! :smile: