Jump to content

Replicate plane movement? I can't comprehend how?


Bricktheworld
 Share

Recommended Posts

Basically, what I am trying to do is replicate the rotation and movement of a plane. Does anyone at all know how to do this? I've been searching for a while and I either can't find anything or I can't understand it. Soooo could anyone explain it to me like I'm five? Thanks! I will also need to be able to receive the rotation vector of the plane at all times.

Link to comment
Share on other sites

Ummm.... I'm not even sure how to start, I guess I can just make a box that moves. Basically, you know how when a plane turns to the left or right it sort of banks on its own z-axis. When turning to the left it turns counterclockwise on its z-axis and when turning right it turns clockwise on its z-axis.  I basically just want to fix this example https://www.babylonjs-playground.com/#RVDXB%234

Link to comment
Share on other sites

42 minutes ago, Bricktheworld said:

Ummm.... I'm not even sure how to start, I guess I can just make a box that moves. Basically, you know how when a plane turns to the left or right it sort of banks on its own z-axis. When turning to the left it turns counterclockwise on its z-axis and when turning right it turns clockwise on its z-axis.  I basically just want to fix this example https://www.babylonjs-playground.com/#RVDXB%234

Like this?

https://www.babylonjs-playground.com/#RVDXB#5

Link to comment
Share on other sites

Ahhh by plane you mean airplane not a mathematical plane.

See if reading this helps http://babylonjsguide.github.io/advanced/Euler_Angles#quaternions-from-euler-angles

You are correct in that you want to simulate the banking of a plane as it turns so you cannot just yaw you have to roll as well. Now things get complicated quite quickly - you want to rotate a little bit about the local z axis (roll) as you rotate a little bit about the local y axis (yaw) to bank the plane. However rolling causes the local y axis to go off vertical and so any yawing about the local y axis will turn the local z axis up or down and so the plane will fly upwards or downwards and to keep the z axis level to the ground you need to pitch as well. Difficult to control using keys

 

Link to comment
Share on other sites

Don't have time to think about it until tomorrow but if you would settle with controlling only the yaw and pitch of the plane then as you turn the plane it should be possible to come up with values for the pitch and roll that would bank the plane and keep it on a level flight. If that would be OK I will think about how it could be done.

I suppose if you wanted full control then a mouse for yaw and roll plus keys for pitch might make a controllable plane for a user.

Link to comment
Share on other sites

I would just like a simple control for the user in which when the user wants to turn to the left or right, he can do it easily(hitting the arrow key or mouseX position, preferably mouse) and still have a semi-accurate movement of a plane. And keep in mind that I will need to be able to retrieve the accurate rotation of the plane at all times. Thanks for your effort :)

Link to comment
Share on other sites

Hello! This is exactly what I need. But I want to add a few more things. First, I will need to be able to retrieve the rotation of the craft(I can't do this right now with console.log(craft.rotation)) and second, I would like it so that when you hold down "A" or "D," it doesn't turn all the way upside down. I would like to restrict the z rotation to maybe 45 degrees. Thanks for helping me out!

Link to comment
Share on other sites

You will have to get the rotation using rotationQuaternion

as using rotate sets rotationQuaternion and sets rotation to zero. If you then want the x, y, and z values to use with rotation use http://babylonjsguide.github.io/advanced/Euler_Angles#euler-angles-from-quaternions

See also http://doc.babylonjs.com/overviews/how_rotations_and_translations_work

You could also keep a running total for rotations around Y or Z axis and set incremental rotation around Z to 0 when it gets more than Math.PI/4 ( or less than -Math.PI/4 in other direction)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...