I am trying to sketch a very simple helicopter-controlling script.
I am using a rigidbody for the body of the helicopter, and then applying an upwards force for sustentation, and torque for maneuvers.
Torque should be applied to the object around it’s local axes, right? But the engine only allows for world space coordinates using the applyTorque() method.
I thought this line of code would make it all better…
* *var tT = this.entity.getRotation().transformVector(torque);* *
… and it kind of does. But torque’s direction changes sign depending on the orientation of the body. For example: “W” key affects pitch, but sometimes it’s applied clockwise and sometimes is applied counter-clockwise.
Another problem I am facing here is the movement of the helices. They get completely misaligned during flight.
Any advice on how should I approach this problems?
Here go the links for the proyect:
First part is solved now . I was setting the torque in x,y and z from right, up and forward vectors. I thought that would help me keep forces relative to each axis, but that was actually just inverting the direction of the torque depending on the orientation. Now I am just giving a fixed value (1 or -1) for torque on each axis.
Next thing is the helices rotation. They are child of my helicopter, but I am not using a rigidbody to rotate them. Every time my helicopter hits the floor, the helices rotation axis gets twisted. I guess it may have something to do with the code for the helices movement interfering with rigidbody calculations.
OK, this is completely solved now. Now I think it was silly to ask in the first place.
I was scripting the rotation of the helices this way:
but the “up” axis of the parent entity moves and turns a lot. I am guessing the euler angles get all messed up when the axis of rotation gets inverted.
Instead of going with quats, I decided to go simple and now i am just scripting the rotation to do:
As long as the helices are child of the entity that is moving, the y axis will always match with the parent’s y axis.