Skip to content

Commit

Permalink
Propeller animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hykudoru committed Dec 5, 2020
1 parent 1c80484 commit 8e59c3b
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions Drones/Assets/Drones/Drone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Drone : MonoBehaviour
Vector3 move = Vector3.zero;
Vector3 throttle = Vector3.zero;

Vector3 thrust;

void Awake()
{
Expand All @@ -44,46 +45,44 @@ private void OnDisable()
{
input.Drone.Disable();
}



private void Update()
{
moveInput = input.Drone.Move.ReadValue<Vector2>();
throttleInput = input.Drone.Throttle.ReadValue<float>();
yawInput = input.Drone.Rotate.ReadValue<float>();

move = (drone.transform.right * moveInput.x + transform.forward * moveInput.y) * moveSpeed;
move.y = 0;
throttle = drone.transform.up * throttleInput * throttleSpeed;

yaw += yawInput * yawSpeed * Time.deltaTime;
roll = moveInput.x * maxRollDeg;
pitch = moveInput.y * maxPitchDeg;


move = (drone.transform.right * moveInput.x + transform.forward * moveInput.y) * moveSpeed;
move.y = 0;
throttle = drone.transform.up * throttleInput * throttleSpeed;

thrust = move + throttle;
// cancel gravity
if (counterGravity && drone.useGravity)
{
thrust += -Physics.gravity;// * Time.deltaTime;
}
}

private void FixedUpdate()
{
{
// roll/pitch/yaw
Quaternion targetRotation = Quaternion.AngleAxis(yaw, Vector3.up)
* Quaternion.AngleAxis(roll, -Vector3.forward)
* Quaternion.AngleAxis(pitch, Vector3.right);
drone.transform.localRotation = Quaternion.Slerp(drone.transform.localRotation, targetRotation, tiltSpeed * Time.deltaTime);

// cancel gravity
if (counterGravity && drone.useGravity)
{
drone.velocity += -Physics.gravity * Time.deltaTime;
}

//move up/down/left/right/forward/back
drone.velocity += move * Time.deltaTime;
drone.velocity += throttle * Time.deltaTime;
drone.velocity += thrust * Time.deltaTime;
}

private void LateUpdate()
{
//float currentPropellerSpeed = Mathf.Clamp(throttle.sqrMagnitude, 0f, 10f);
//animator.SetFloat("Thrust", currentPropellerSpeed);
float currentPropellerSpeed = Mathf.Clamp(thrust.sqrMagnitude, 0f, 10f);
animator.SetFloat("Thrust", currentPropellerSpeed);
}
}

0 comments on commit 8e59c3b

Please sign in to comment.