Skip to content

Help with drone fly controls #423

Discussion options

You must be logged in to vote

Sometimes all you need is a good night's sleep.

  1. Subscribe to the entity's rotation (getting a Quad)
  2. Make a THREE.Quaternion from that Quad.
  3. Use a THREE.Vector3 to represent torque and apply the Quaternion to it before passing it to the API.
const unitVector = new THREE.Vector3();
const unitQuaternion = new THREE.Quaternion();
const quaternion = useRef<Quad>([0, 0, 0, 1]);
api.quaternion.subscribe((val) => (quaternion.current = val));
const qc = quaternion.current;
const q = unitQuaternion.set(qc[0], qc[1], qc[2], qc[3]);
const v = unitVector.set(
  pitch.current * torqueScale, 0,roll.current * torqueScale
);

v.applyQuaternion(q);
api.applyTorque(v.toArray());

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DavidBachmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant