Skip to content

Commit

Permalink
99.99
Browse files Browse the repository at this point in the history
  • Loading branch information
Hykudoru committed Nov 28, 2020
1 parent a9bf772 commit 62b7626
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
76 changes: 45 additions & 31 deletions Drones/Assets/Drones/Drone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ public class Drone : MonoBehaviour
{
Rigidbody drone;
DroneInput input;
[SerializeField] [Range(1, 60f)] float maxDegPitchRoll = 28f;
[SerializeField] float rollPitchSpeed = 50f;
[SerializeField] float moveSpeed = 50f;
[SerializeField] float throttleSpeed = 50f;
[SerializeField] float yawTurnSpeed = 360f;
[SerializeField] float yawSpeed = 360f;
[SerializeField] float tiltSpeed = 50f;
[SerializeField] [Range(1, 60f)] float maxRollDeg = 28f;
[SerializeField] [Range(1, 60f)] float maxPitchDeg = 28f;
[SerializeField] [Range(1, 60f)] float maxTiltDeg = 28f;
[SerializeField] float maxAltitude = Mathf.Infinity;
[SerializeField] float maxDisplacement = Mathf.Infinity;

float roll;
float pitch;
float yaw;
Vector3 move = Vector3.zero;
Vector3 throttle = Vector3.zero;


void Awake()
{
drone = GetComponent<Rigidbody>();
Expand All @@ -34,45 +40,33 @@ private void OnDisable()
input.Drone.Disable();
}

Vector2 moveInput;
float throttleInput;
float yawInput;

private void Update()
{
Vector2 moveInput = input.Drone.Move.ReadValue<Vector2>();
float throtteInput = input.Drone.Throttle.ReadValue<float>();
float yawInput = input.Drone.Rotate.ReadValue<float>();
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 * throtteInput * throttleSpeed;

roll = moveInput.x * maxDegPitchRoll;// rollPitchSpeed;
pitch = moveInput.y * maxDegPitchRoll;// rollPitchSpeed;
yaw = yawInput * yawTurnSpeed;
throttle = drone.transform.up * throttleInput * throttleSpeed;

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

}

float rotation;

private void FixedUpdate()
{/*
rotation += new Vector3(pitch, yaw, roll) * Time.deltaTime;
rotation.x = Mathf.Clamp(rotation.x, -maxDegPitchRoll, maxDegPitchRoll);
rotation.z = Mathf.Clamp(rotation.z, -maxDegPitchRoll, maxDegPitchRoll);
drone.transform.localRotation = Quaternion.Euler(rotation);
*/
//drone.transform.localRotation = Quaternion.Slerp(drone.transform.localRotation, targetRot, rollPitchSpeed * Time.deltaTime);
//drone.transform.localRotation *= Quaternion.Euler(Vector3.up * yaw * Time.deltaTime);

// roll/pitch/yaw
//var rotAxis = Vector3.Cross(drone.transform.up, move);
//drone.transform.localRotation = Quaternion.Euler(rotation) *Quaternion.AngleAxis(maxDegPitchRoll, rotAxis);
//drone.angularVelocity = Vector3.up * yaw * Time.deltaTime;


{
// roll/pitch/yaw
var targetRotation = Quaternion.AngleAxis(yaw*Time.deltaTime, Vector3.up)
var targetRotation = Quaternion.AngleAxis(yaw*yawSpeed*Time.deltaTime, Vector3.up)
* Quaternion.AngleAxis(roll, -Vector3.forward)
* Quaternion.AngleAxis(pitch, Vector3.right);

drone.transform.localRotation = Quaternion.Slerp(drone.transform.rotation, targetRotation, 20 * Time.deltaTime);
drone.transform.localRotation = targetRotation;//Quaternion.Slerp(drone.transform.localRotation, targetRotation, 20 * Time.deltaTime);

// cancel gravity
if (drone.useGravity)
Expand All @@ -84,4 +78,24 @@ private void FixedUpdate()
drone.velocity += move * Time.deltaTime;
drone.velocity += throttle * Time.deltaTime;
}

private void LateUpdate()
{

}

private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawRay(transform.position, drone.transform.TransformDirection(10f, 0f, 0f));
Gizmos.color = Color.blue;
Gizmos.DrawRay(transform.position, drone.transform.TransformDirection(0, 0, 10f));

Gizmos.color = Color.green;
Gizmos.DrawRay(transform.position, drone.transform.TransformDirection(moveInput.x, 0, moveInput.y)*200);
Gizmos.color = Color.gray;
Gizmos.DrawRay(transform.position, drone.transform.TransformDirection(move));
Gizmos.color = Color.black;
Gizmos.DrawRay(transform.position, move);
}
}
2 changes: 1 addition & 1 deletion Drones/Assets/Drones/DroneScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ PrefabInstance:
- target: {fileID: 3541209806302926729, guid: 9feb64c7d592fb247ae0139596c5abc1,
type: 3}
propertyPath: m_LocalPosition.y
value: 1
value: 0.4
objectReference: {fileID: 0}
- target: {fileID: 3541209806302926729, guid: 9feb64c7d592fb247ae0139596c5abc1,
type: 3}
Expand Down

0 comments on commit 62b7626

Please sign in to comment.