Hi, I’m new and I still getting used to programming again.
We have a space ship which moves left, right, front, back with the arrows and we want it to move left and right and go 45º rotated when do it and go back to 0º when you stop clicking.
But what we have been able to do is to made it rotate 45º every time we clicked and even if we manage to made it back to 0º, the translation is with space ship axis (rotated 45º) instead the world axis.
I hope I explained myself fine, if not I can provide more info.
Thanks for the help.
=^^= =^^= =^^=
Problem auto solved/shot
Thanks for all the help and sorry for troubles.
The final code is like this
We have a file applied to the player (player_control)
var playerSpeed : float;
//var engineSound : GameObject;
function Start () {
}
function Update () {
transform.Translate(Input.GetAxisRaw("Horizontal") * Time.deltaTime * playerSpeed, 0, Input.GetAxisRaw("Vertical") * Time.deltaTime * playerSpeed);
transform.position.x = Mathf.Clamp(transform.position.x, -45, 45);
transform.position.z = Mathf.Clamp(transform.position.z, -20, 20);
}
And a file aplied to the spaceship (player_angle)
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.RightArrow)) {
transform.Rotate(Vector3(0.0, 30, 0.0));
}
else if (Input.GetKeyUp(KeyCode.RightArrow)) {
transform.Rotate(Vector3(0.0, -30, 0.0));
}
if(Input.GetKeyDown(KeyCode.LeftArrow)) {
transform.Rotate(Vector3(0.0, -30, 0.0));
}
else if (Input.GetKeyUp(KeyCode.LeftArrow)) {
transform.Rotate(Vector3(0.0, 30, 0.0));
}
}
So now the spaceship rotates, but don’t affect to the movement.