Мне нужно при крене самолета возвращать его в исходную позицию. В этом скрипте из геликоптер туториала это есть, но я незнаю где. Подскажите плиз!
Code
var main_Rotor_GameObject : GameObject; // gameObject to be animated var tail_Rotor_GameObject : GameObject; // gameObject to be animated
var max_Rotor_Force : float = 22241.1081; // newtons static var max_Rotor_Velocity : float = 7200; // degrees per second private var rotor_Velocity : float = 0.0; // value between 0 and 1 private var rotor_Rotation : float = 0.0; // degrees... used for animating rotors
var max_tail_Rotor_Force : float = 15000.0; // newtons var max_Tail_Rotor_Velocity : float = 2200.0; // degrees per second private var tail_Rotor_Velocity : float = 0.0; // value between 0 and 1 private var tail_Rotor_Rotation : float = 0.0; // degrees... used for animating rotors
var forward_Rotor_Torque_Multiplier : float = 0.5; // multiplier for control input var sideways_Rotor_Torque_Multiplier : float = 0.5; // multiplier for control input
static var main_Rotor_Active : boolean = true; // boolean for determining if a prop is active static var tail_Rotor_Active : boolean = true; // boolean for determining if a prop is active
// Forces are applied in a fixed update function so that they are consistent no matter what the frame rate of the game is. This is // important to keeping the helicopter stable in the air. If the forces were applied at an inconsistent rate, the helicopter would behave // irregularly. function FixedUpdate () {
// First we must compute the torque values that are applied to the helicopter by the propellers. The "Control Torque" is used to simulate // the variable angle of the blades on a helicopter and the "Torque Value" is the final sum of the torque from the engine attached to the // main rotor, and the torque applied by the tail rotor. var torqueValue : Vector3; var controlTorque : Vector3 = Vector3( Input.GetAxis( "Vertical" ) * forward_Rotor_Torque_Multiplier, 1.0, -Input.GetAxis( "Horizontal2" ) * sideways_Rotor_Torque_Multiplier );
// Now check if the main rotor is active, if it is, then add it's torque to the "Torque Value", and apply the forces to the body of the // helicopter. if ( main_Rotor_Active == true ) { torqueValue += (controlTorque * max_Rotor_Force * rotor_Velocity);
// Now the force of the prop is applied. The main rotor applies a force direclty related to the maximum force of the prop and the // prop velocity (a value from 0 to 1) rigidbody.AddRelativeForce( Vector3.up * max_Rotor_Force * rotor_Velocity );
// This is simple code to help stabilize the helicopter. It essentially pulls the body back towards neutral when it is at an angle to // prevent it from tumbling in the air. if ( Vector3.Angle( Vector3.up, transform.up ) < 80 ) { transform.rotation = Quaternion.Slerp( transform.rotation, Quaternion.Euler( 0, transform.rotation.eulerAngles.y, 0 ), Time.deltaTime * rotor_Velocity * 3 ); } }
// Now we check to make sure the tail rotor is active, if it is, we add it's force to the "Torque Value" if ( tail_Rotor_Active == true ) { torqueValue -= (Vector3.up * max_tail_Rotor_Force * tail_Rotor_Velocity); }
// And finally, apply the torques to the body of the helicopter. rigidbody.AddRelativeTorque( torqueValue ); }
function Update () { // This line simply changes the pitch of the attached audio emitter to match the speed of the main rotor. audio.pitch = rotor_Velocity;
// Now we animate the rotors, simply by setting their rotation to an increasing value multiplied by the helicopter body's rotation. if ( main_Rotor_Active == true ) { main_Rotor_GameObject.transform.rotation = transform.rotation * Quaternion.Euler( 0, rotor_Rotation, 0 ); } if ( tail_Rotor_Active == true ) { tail_Rotor_GameObject.transform.rotation = transform.rotation * Quaternion.Euler( tail_Rotor_Rotation, 0, 0 ); }
// this just increases the rotation value for the animation of the rotors. rotor_Rotation += max_Rotor_Velocity * rotor_Velocity * Time.deltaTime; tail_Rotor_Rotation += max_Tail_Rotor_Velocity * rotor_Velocity * Time.deltaTime;
// here we find the velocity required to keep the helicopter level. With the rotors at this speed, all forces on the helicopter cancel // each other out and it should hover as-is. var hover_Rotor_Velocity = (rigidbody.mass * Mathf.Abs( Physics.gravity.y ) / max_Rotor_Force); var hover_Tail_Rotor_Velocity = (max_Rotor_Force * rotor_Velocity) / max_tail_Rotor_Force;
// Now check if the player is applying any throttle control input, if they are, then increase or decrease the prop velocity, otherwise, // slowly LERP the rotor speed to the neutral speed. The tail rotor velocity is set to the neutral speed plus the player horizontal input. // Because the torque applied by the main rotor is directly proportional to the velocity of the main rotor and the velocity of the tail rotor, // so when the tail rotor velocity decreases, the body of the helicopter rotates. if ( Input.GetAxis( "Vertical2" ) != 0.0 ) { rotor_Velocity += Input.GetAxis( "Vertical2" ) * 0.008; }else{ rotor_Velocity = Mathf.Lerp( rotor_Velocity, hover_Rotor_Velocity, Time.deltaTime * Time.deltaTime * 30 ); } tail_Rotor_Velocity = hover_Tail_Rotor_Velocity - Input.GetAxis( "Horizontal" );
// now we set velocity limits. The multiplier for rotor velocity is fixed to a range between 0 and 1. You can limit the tail rotor velocity // too, but this makes it more difficult to balance the helicopter variables so that the helicopter will fly well. if ( rotor_Velocity > 1.0 ) { rotor_Velocity = 1.0; }else if ( rotor_Velocity < 0.0 ) { rotor_Velocity = 0.0; } }
Сообщение отредактировал VolkOrievith - Чт, 13 Дек 2012, 15:34
Я перевел в своей проге, и ненашел то, что мне нужно. Вот что получилось:
Сначала мы должны вычислить величины вращающего момента, которые приложены к вертолету винтами. "Управляющий Вращающий момент" использован, чтобы имитировать // переменный угол лопастей на вертолете и "Величина Вращающего момента" является конечной суммой вращающего момента из двигателя приложенного к // основному ротору, и вращающий момент прилагался ротором хвоста. Теперь чек если основной ротор активен, если он -, тогда добавьте этому - вращающий момент в "Величине Вращающего момента", и приложите силы к телу // вертолета. Теперь усилие подпорки приложено. Основной ротор прилагает принудительный direclty имело отношение к максимальному усилию подпорки и // скорость подпорки ( величина от 0 до 1) // Это - простой код, чтобы помогать стабилизировать вертолет. Это по существу тянет тело к нейтральному когда это - в углу // предохранять это от поворота в неопределенном положении. Теперь мы проверяем, чтобы убеждаться что ротор хвоста активен, если он, мы добавляем этому - усилие в "Величине Вращающего момента" И наконец, прилагает вращающие моменты к телу вертолета.Эта линия просто изменяет шаг прилагаемого аудио эмитента, чтобы соответствовать скорости основного ротора.Теперь мы оживляем роторы, просто устанавливая их вращение в возрастающую величину умноженную на вертолет воплощать rotation. это просто увеличивает величину вращения для оживления rotors.here, которое мы находим скорость требовавшуюся, чтобы держать уровень вертолета. С роторами в этой скорости, все силы на вертолете отменяют // друг друга и это должно реять как-.Теперь чек если игрок прилагает любой управляющий вклад дросселя, если они -, тогда увеличьте или уменьшайте скорость подпорки, в противном случае, // медленно LERP скорость ротора в нейтральную скорость. Скорость ротора хвоста установлена в нейтральную скорость плюс горизонтальный вклад игрока. // Поскольку вращающий момент приложенный основным ротором непосредственно пропорциональный в скорость основного ротора и скорость ротора хвоста, // так когда уменьшения скорости ротора хвоста, тело вертолета rotates.now, мы установили пределы скорости. Множитель для скорости ротора установлен в дипазон между 0 и 1. Вы можете ограничить скорость / ротор хвоста/ тоже, но это делает это более трудно, чтобы балансировать переменные вертолета чтобы вертолет полетал хорошо.
Добавлено (13.12.2012, 20:08) --------------------------------------------- Почему у меня комп УЖАСНО тормозит от этих строк:
Code
// prevent it from tumbling in the air. if ( Vector3.Angle( Vector3.up, transform.up ) < 80 ) { transform.rotation = Quaternion.Slerp( transform.rotation, Quaternion.Euler( 0, transform.rotation.eulerAngles.y, 0 ), Time.deltaTime * rotor_Velocity * 3 ); }