turn 180 spaceship

 0 Hello UAExcuse my English, I tell them what my problem.I'm programming the physics for a spacecraft, I've managed to turn like an airplane, when you move to the sides, and am now developing the 180 degree turn. I succeeded, but my problem is that this rotation depends on the time so I have developed. He commented that the turn has first to turn on the X axis to show the bottom of the spacecraft, and then rotate in the Z axis to return to the right side.This shift should be discontinued at any time and start again, in the sense that is given to ASWD.I would not be so, as you should be able to change the sense of direction at the moment is making the turn. I spent a bit of code, clarified that the move to the sense in watching the ship, already developed elsewhere. turnSpeed = 7.0f; tiltSpeed = 3.0f; tiltAngle = 40.0f; angle = 0.0f; dir = 1.0f; terminoGiro = true; parte1 = false; parte2 = false; duracionGiro = new LinearInterpolator(0,1,1); void Girando() { horizontalDirectionTurn = Input.GetAxis("Horizontal"); verticalDirectionTurn = Input.GetAxis("Vertical"); dTime = Time.deltaTime; desiredDirection = new Vector3(horizontalDirectionTurn, 0, verticalDirectionTurn).normalized; if (terminoGiro) { if (!desiredDirection.Equals(Vector3.zero)) { if ((Vector3.Angle(desiredDirection,transform.forward) > 2) && (Vector3.Angle(desiredDirection,transform.forward) < 100)) { if (Vector3.Cross(desiredDirection, currentDirection).y > 0.0f) { dir = 1.0f; } else { dir = -1.0f; } angle += tiltSpeed * dTime; currentDirection = Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime); angle = Mathf.Clamp(angle, 0.0f, 1.0f); transform.LookAt(transform.position + currentDirection); body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir); } else if (Vector3.Angle(desiredDirection,transform.forward) > 100) { terminoGiro = false; parte1 = true; } else { angle -= tiltSpeed * dTime; angle = Mathf.Clamp(angle, 0.0f, 1.0f); transform.LookAt(transform.position + currentDirection); body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir); } } else { angle = 0; angle = Mathf.Clamp(angle, 0.0f, 1.0f); transform.LookAt(transform.position + currentDirection); body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir); } } else { if(parte1) { currentDirection = Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime); transform.Rotate(-180 * dTime,0,0,Space.Self); duracionGiro.Interpolate(); //timer 1s if (duracionGiro.HasFinished()) //timer finish? { duracionGiro.Reset(); parte2 = true; parte1 = false; } } if (parte2) { currentDirection = Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime); transform.Rotate(0,0,180 * dTime,Space.Self); duracionGiro.Interpolate(); if(duracionGiro.HasFinished()) { duracionGiro.Reset(); parte2 = false; terminoGiro = true; transform.LookAt(transform.position + currentDirection); } } } } From already thank you very much more ▼ asked Jul 15 '11 at 03:11 PM bgnoatto 26 ● 2 ● 3 ● 5 SisterKy 2.5k ● 33 ● 42 ● 60 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

Be the first one to answer this question

By Email:

Topics:

x300
x51
x43
x38
x1

asked: Jul 15 '11 at 03:11 PM

Seen: 494 times

Last Updated: Jul 17 '11 at 10:10 AM