Skip to content

Commit

Permalink
New Input system
Browse files Browse the repository at this point in the history
Gamecontroller + GUI Controlls
  • Loading branch information
Hykudoru committed Nov 27, 2020
1 parent 6a56ecd commit 02fd6b6
Show file tree
Hide file tree
Showing 21 changed files with 2,626 additions and 48 deletions.
81 changes: 36 additions & 45 deletions Drones/Assets/Drones/Drone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,65 @@
public class Drone : MonoBehaviour
{
Rigidbody drone;
[SerializeField] [Range(1, 60f)] float deg = 28f;
[SerializeField] float thrust = 50f;
[SerializeField] float turnSpeed = 360f;
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;
float roll;
float pitch;
float yaw;
Vector3 verticalThrust;
Vector3 horizontalThrust;
//Vector3 angularVelocity;
Vector3 move = Vector3.zero;
Vector3 throttle = Vector3.zero;

void Awake()
{
drone = GetComponent<Rigidbody>();
input = new DroneInput();
}
/*
// Update is called once per frame
void Update()
{
angularVelocity.y = Input.GetAxis("Horizontal") * turnSpeed;
velocity.y = Input.GetAxis("Vertical");

move = (transform.right * Input.GetAxis("Horizontal-2")+transform.forward * Input.GetAxis("Vertical-2"));
private void OnEnable()
{
input.Drone.Enable();
}

private void FixedUpdate()
private void OnDisable()
{
drone.velocity += (velocity * thrust + move* moveSpeed)*Time.deltaTime;
drone.angularVelocity = angularVelocity;
}*/
input.Drone.Disable();
}

float _speed = 5;
float _v1;
float _v2;
private void Update()
{
yaw += Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
roll = Input.GetAxis("Horizontal-2") * deg;
pitch = Input.GetAxis("Vertical-2") * deg;

verticalThrust = drone.transform.up * Input.GetAxis("Vertical") * thrust * Time.deltaTime;
horizontalThrust = (drone.transform.forward * pitch + drone.transform.right * roll) * drone.drag * Time.deltaTime;
horizontalThrust.y = 0;
Vector2 moveInput = input.Drone.Move.ReadValue<Vector2>();
float throtteInput = input.Drone.Throttle.ReadValue<float>();
float yawInput = input.Drone.Rotate.ReadValue<float>();

_v1 = Input.GetAxis("Mouse Y") * _speed * Time.deltaTime;
move = (drone.transform.right * moveInput.x + transform.forward * moveInput.y) * moveSpeed;
move.y = 0;
throttle = drone.transform.up * throtteInput * throttleSpeed;

roll = move.x * maxDegPitchRoll;// rollPitchSpeed;
pitch = move.z * maxDegPitchRoll;// rollPitchSpeed;
yaw = yawInput * yawTurnSpeed;
}

private void FixedUpdate()
{

_v2 = Input.GetAxis("Mouse Y") *_speed * Time.deltaTime;

{
// roll/pitch/yaw
drone.transform.localRotation = Quaternion.AngleAxis(yaw, Vector3.up)
* Quaternion.AngleAxis(roll*deg*Time.deltaTime, -Vector3.forward)
* Quaternion.AngleAxis(pitch*deg*Time.deltaTime, Vector3.right);
//var rotAxis = Vector3.Cross(drone.transform.up, move);
//drone.transform.localRotation = Quaternion.AngleAxis(rotate, Vector3.up) * Quaternion.AngleAxis(maxDegPitchRoll, rotAxis);
//drone.angularVelocity = Vector3.up * yaw * Time.deltaTime;

//move up/down/left/right/forward/back
drone.velocity += verticalThrust + horizontalThrust;
// cancel gravity
if (drone.useGravity)
{
drone.velocity += -Physics.gravity * Time.deltaTime;
}

//cancel / equal - gravity 0 angle relative to world
// drone.velocity += drone.transform.up * -Physics.gravity.y * Time.deltaTime;
//drone.velocity += -Physics.gravity *(1 - Vector3.Dot(drone.transform.up, Vector3.up)) * Time.deltaTime;
}
//move up/down/left/right/forward/back
drone.velocity += move * Time.deltaTime;
drone.velocity += throttle * Time.deltaTime;

private void LateUpdate()
{
Debug.Log(_v1);
Debug.Log(_v2);
}
}
Loading

0 comments on commit 02fd6b6

Please sign in to comment.