# RC Airplane orientation

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So there's this RC airplane flying around. The camera is fixed and the user just flies the RC airplane around by moving it's position in 3D. What I have is the plane's position history (xyz pairs). How can I make it so that the airplane banks left when it turns left , pitches up when gaining altitude etc?

Jubei

##### Share on other sites
Any solution to this problem will (probably) necessarily be ad hoc (since there's no 'real physics' involved), but here's a couple of suggestions.

First of all, you can compute the absolute pitch and yaw for the plane from the vector from the previous position to the current position (provided the difference vector has sufficient magnitude). This should give the basic orientation for the plane at any given time, although there will be no rolling/banking.

Once you've computed the 'base' orientation using a from-scratch Euler-angle construction (using the pitch and yaw angles), I think you could then roll the plane locally about its forward vector to create a 'banking' effect.

All you need then is the angle to bank by. One way to compute this angle would be as follows (pseudocode):

vector3 v1 = position[i - 1] - position[i - 2]; vector3 v2 = position - position[i - 1]; // project_to_ground_plane() would zero out the element corresponding to the world 'up' vector. v1 = project_to_ground_plane(v1); v2 = project_to_ground_plane(v2); float roll_angle = signed_angle_with_respect_to_ground_plane(v1, v2) * roll_factor;
Note that this code assumes v1 and v2 both have non-negligible magnitude after being projected.

Obviously this skips over some details, and it's somewhat speculative as well (I haven't tried this exact method myself).

##### Share on other sites
The game would probably be a lot more fun if it did involve Physics. In that case, the state of the plane at a given time has both the position (x,y,z) and the attitude (either as (roll, pitch, yaw), a quaternion or a rotation matrix).

• 18
• 11
• 16
• 9
• 51
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999789
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!