Skip to content

Instantly share code, notes, and snippets.

@jasonhbartlett
Created December 11, 2018 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonhbartlett/ed18709acabc8ef1e34bed276c5e32b7 to your computer and use it in GitHub Desktop.
Save jasonhbartlett/ed18709acabc8ef1e34bed276c5e32b7 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using AirSimUnity.DroneStructs;
using UnityEngine;
namespace AirSimUnity
{
[RequireComponent(typeof(Drone))]
public class DroneControllerInput : MonoBehaviour
{
private Drone drone;
private void Start() {
drone = this.gameObject.GetComponent<Drone>();
}
private void LateUpdate()
{
if (drone.ControllerAllowed())
{
AirSimRCData rcData = drone.GetRCData();
rcData.is_valid = true;
rcData.roll = Input.GetAxis("Horizontal");
rcData.pitch = Input.GetAxis("Vertical");
rcData.throttle = Input.GetAxis("Depth");
rcData.yaw = Input.GetAxis("Yaw");
rcData.left_z = 0;
rcData.right_z = 0;
rcData.switch1 = (uint)(Input.GetKeyDown("joystick button 0") ? 1 : 0);
rcData.switch2 = (uint)(Input.GetKeyDown("joystick button 1") ? 1 : 0);
rcData.switch3 = (uint)(Input.GetKeyDown("joystick button 2") ? 1 : 0);
rcData.switch4 = (uint)(Input.GetKeyDown("joystick button 3") ? 1 : 0);
rcData.switch5 = (uint)(Input.GetKeyDown("joystick button 4") ? 1 : 0);
rcData.switch6 = (uint)(Input.GetKeyDown("joystick button 5") ? 1 : 0);
rcData.switch7 = (uint)(Input.GetKeyDown("joystick button 6") ? 1 : 0);
rcData.switch8 = (uint)(Input.GetKeyDown("joystick button 7") ? 1 : 0);
drone.SetRCData(rcData);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment