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);
}
}
}