i have a purchased asset with a that uses amodified version of the helicopter controller script that is on the internet, i would like to convert it to use mouse to control the pitch and tilt/roll
can anyone help me convert it so it still has the smooth movement that happens when press the keys
thank you in advance
here is control part of script:
void FixedUpdate()
{
LiftProcess();
MoveProcess();
TiltProcess();
}
private void MoveProcess()
{
var turn = TurnForce * Mathf.Lerp(hMove.x, hMove.x * (turnTiltForcePercent - Mathf.Abs(hMove.y)), Mathf.Max(0f, hMove.y));
hTurn = Mathf.Lerp(hTurn, turn, Time.fixedDeltaTime * TurnForce);
myRigidbody.AddRelativeTorque(0f, hTurn * myRigidbody.mass, 0f);
myRigidbody.AddRelativeForce(Vector3.forward * Mathf.Max(0f, hMove.y * ForwardForce * myRigidbody.mass));
}
private void LiftProcess()
{
var upForce = 1 - Mathf.Clamp(myRigidbody.transform.position.y / EffectiveHeight, 0, 1);
upForce = Mathf.Lerp (0f, EngineForce, upForce)* myRigidbody.mass;
myRigidbody.AddRelativeForce(Vector3.up * upForce);
}
private void TiltProcess()
{
hTilt.x = Mathf.Lerp(hTilt.x, hMove.x * TurnTiltForce, Time.deltaTime);
hTilt.y = Mathf.Lerp(hTilt.y, hMove.y * ForwardTiltForce, Time.deltaTime);
myRigidbody.transform.localRotation = Quaternion.Euler(hTilt.y, myRigidbody.transform.localEulerAngles.y, -hTilt.x);
}
private void OnKeyPressed(PressedKeyCode[] obj)
{
float tempY = 0;
float tempX = 0;
// stable forward
if (hMove.y > 0)
tempY = - Time.fixedDeltaTime;
else
if (hMove.y < 0)
tempY = Time.fixedDeltaTime;
// stable lurn
if (hMove.x > 0)
tempX = -Time.fixedDeltaTime;
else
if (hMove.x < 0)
tempX = Time.fixedDeltaTime;
foreach (var pressedKeyCode in obj)
{
switch (pressedKeyCode)
{
case PressedKeyCode.SpeedUpPressed:
EngineForce += 1f;
break;
case PressedKeyCode.SpeedDownPressed:
EngineForce -= 1f;
if (EngineForce < 0) EngineForce = 0;
break;
case PressedKeyCode.ForwardPressed:
if (IsOnGround) break;
tempY = Time.fixedDeltaTime;
break;
case PressedKeyCode.BackPressed:
if (IsOnGround) break;
tempY = -Time.fixedDeltaTime;
break;
case PressedKeyCode.LeftPressed:
if (IsOnGround) break;
tempX = -Time.fixedDeltaTime;
break;
case PressedKeyCode.RightPressed:
if (IsOnGround) break;
tempX = Time.fixedDeltaTime;
break;
case PressedKeyCode.TurnRightPressed:
{
if (IsOnGround) break;
var force = (turnForcePercent - Mathf.Abs(hMove.y))*myRigidbody.mass;
myRigidbody.AddRelativeTorque(0f, force, 0);
}
break;
case PressedKeyCode.TurnLeftPressed:
{
if (IsOnGround) break;
var force = -(turnForcePercent - Mathf.Abs(hMove.y))*myRigidbody.mass;
myRigidbody.AddRelativeTorque(0f, force, 0);
}
break;
}
}
hMove.x += tempX;
hMove.x = Mathf.Clamp(hMove.x, -1, 1);
hMove.y += tempY;
hMove.y = Mathf.Clamp(hMove.y, -1, 1);
}