- Home /
Question by
R00dy · Jan 06, 2015 at 04:23 PM ·
Model keeps flipping on its side
Hi, when i test my game the tank flips on its side when i move it about with the WSAD keys it moves fine but as i said its on its side which i dont want and i can't figure where the problem is. ive try'd fiddling with the character controller but that hasnt fixed the problem. here is my code and pictures:
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (CharacterController))]
public class PlayerController : MonoBehaviour {
//Handling
public float rotationSpeed = 450;
public float walkSpeed = 5;
public float runSpeed = 8;
//System
private Quaternion TargetRotation;
//Components
private CharacterController controller;
void Start () {
controller = GetComponent<CharacterController>();
}
void Update () {
Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical"));
if (input != Vector3.zero){
TargetRotation = Quaternion.LookRotation(input);
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y,TargetRotation.eulerAngles.y,rotationSpeed * Time.deltaTime);
}
Vector3 Motion = input;
Motion *= (Mathf.Abs (input.x) == 1 && Mathf.Abs (input.z) == 1)?.7f:1;
Motion *= (Input.GetButton ("Run")) ? runSpeed : walkSpeed;
controller.Move (Motion * Time.deltaTime);
tank.png
(136.5 kB)
tank 2.png
(94.3 kB)
Comment
Answer by tanoshimi · Jan 06, 2015 at 05:32 PM
This line looks peculiar: (if nothing else, because you've got eulerAngles.y in there twice?)
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y,TargetRotation.eulerAngles.y,rotationSpeed * Time.deltaTime);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Delete object when two collision or more 1 Answer
Vector3 being treated as a variable 1 Answer
Terrain isn`t working PLEASE help 2 Answers