-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
namespace AirControl | ||
{ | ||
public class AC_BaseAirplane_Input : MonoBehaviour | ||
{ | ||
#region Variable | ||
|
||
protected float pitch = 0f; | ||
protected float roll = 0f; | ||
protected float yaw = 0f; | ||
protected float throttle = 0f; | ||
protected float brake = 0f; | ||
public int maxFlapIncrements=2; // maximum increment allowed to flaps | ||
protected int flaps = 0; | ||
#endregion | ||
|
||
#region Properties | ||
public float Pitch{ | ||
get{return pitch;} | ||
} | ||
public float Roll{ | ||
get{return roll;} | ||
} | ||
public float Yaw{ | ||
get{return yaw;} | ||
} | ||
public float Throttle{ | ||
get{return throttle;} | ||
} | ||
public int Flaps{ | ||
get{return flaps;} | ||
} | ||
public float Brake{ | ||
get{return brake;} | ||
} | ||
#endregion | ||
|
||
|
||
#region Builtin Methods | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
|
||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
HandleInput(); | ||
} | ||
#endregion | ||
|
||
#region Custom Methods | ||
protected virtual void HandleInput(){ | ||
// Process pitch, roll, yaw and throttle | ||
pitch = Input.GetAxis("Vertical"); | ||
roll = Input.GetAxis("Horizontal"); | ||
yaw = Input.GetAxis("yaw"); | ||
throttle = Input.GetAxis("throttle"); | ||
// Process brakes bool | ||
brake = Input.GetKey(KeyCode.Space)?1f:0f; | ||
// Process flaps | ||
// get GetKeyDown is used because it fires only once when key pressed. GetKey constantly fire events | ||
if(Input.GetKeyDown(KeyCode.F)){ | ||
flaps+=1; | ||
} | ||
if(Input.GetKeyDown(KeyCode.G)){ | ||
flaps-=1; | ||
} | ||
flaps = Mathf.Clamp(flaps, 0,maxFlapIncrements); | ||
|
||
} | ||
#endregion | ||
} | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
namespace AirControl | ||
{ | ||
public class AC_XboxAirplane_Input : AC_BaseAirplane_Input | ||
{ | ||
#region Variable | ||
|
||
#endregion | ||
|
||
#region Builtin Methods | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
|
||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
|
||
} | ||
#endregion | ||
|
||
#region Custom Methods | ||
/// make sure you update input settings in Unity | ||
/// Then Only Xbox will work properly | ||
/// Refer to resources for setup | ||
// 1. https://answers.unity.com/questions/1350081/xbox-one-controller-mapping-solved.html | ||
// 2. https://www.udemy.com/course/intro-to-airplane-physics-in-unity-3d/learn/lecture/10348654#questions | ||
protected override void HandleInput() | ||
{ | ||
// Process pitch, roll, yaw and throttle | ||
pitch = Input.GetAxis("Vertical"); | ||
roll = Input.GetAxis("Horizontal"); | ||
yaw = Input.GetAxis("X_RH_Stick"); | ||
throttle = Input.GetAxis("X_RV_Stick"); | ||
// Process brakes bool | ||
brake = Input.GetAxis("Fire1"); | ||
// Process flaps | ||
// get GetKeyDown is used because it fires only once when key pressed. GetKey constantly fire events | ||
if(Input.GetButtonDown("X_R_Bumper")){ | ||
flaps+=1; | ||
} | ||
if(Input.GetButtonDown("X_L_Bumper")){ | ||
flaps-=1; | ||
} | ||
flaps = Mathf.Clamp(flaps, 0,maxFlapIncrements); | ||
|
||
} | ||
#endregion | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.