- Home /
Character Rotation - Script not functioning correctly
The problem with the script is that all but one of the diagonal movements are not functioning. I have a feeling that this is because the script is detecting that a key was pressed and not checking if the other key was pressed and going to the diagonal rotation.
JS
public var time: Time;
public var characterModel : GameObject;
function Start () {
time.fixedDeltaTime = 0.01f;
characterModel = GameObject.Find("Gamemodel Combonation");
}
function FixedUpdate () {
var yAngle = GameObject.Find("Main Camera").transform.eulerAngles.y;
if (Input.GetKey(KeyCode.W))
transform.eulerAngles = Vector3(0, yAngle, 0);
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
transform.eulerAngles = Vector3(0, yAngle + 45, 0);
if (Input.GetKey(KeyCode.D))
transform.eulerAngles = Vector3(0, yAngle + 90, 0);
if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.S))
transform.eulerAngles = Vector3(0, yAngle + 135, 0);
if (Input.GetKey(KeyCode.S))
transform.eulerAngles = Vector3(0, yAngle + 180, 0);
if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A))
transform.eulerAngles + Vector3(0, yAngle + 225, 0);
if (Input.GetKey(KeyCode.A))
transform.eulerAngles = Vector3(0, yAngle + 270, 0);
if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.W))
transform.eulerAngles = Vector3(0, yAngle + 315, 0);
}
The script functions but not all the lines work and Unity Debugger doesn't say anything is wrong with it.
Answer by Sisso · May 22, 2014 at 12:41 PM
No questions.... If is not working is because it is wrong. If it is wrong, you need to know why. To know why you need to debug:
https://docs.unity3d.com/Documentation/Manual/Debugger.html
http://answers.unity3d.com/questions/162579/how-to-debug-unity-script.html
Now that you can see what is happening, simple change your code and try again.
Your answer
Follow this Question
Related Questions
Tilt with rotation. 0 Answers
Slerp Problem?: Enemy in Constant Rotation! 1 Answer
Moving Forward 1 Answer
Character Customization 1 Answer