Bricktheworld Posted October 10, 2017 Share Posted October 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
jerome Posted October 10, 2017 Share Posted October 10, 2017 What does "replicate the rotation and movement of a plane" mean ? Could you please make a PG to show us what you're trying to do ? Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted October 10, 2017 Author Share Posted October 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
Raggar Posted October 10, 2017 Share Posted October 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 10, 2017 Share Posted October 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted October 10, 2017 Author Share Posted October 10, 2017 Thank you guys! Do you think its possible to do this JohnK using mouse controls or any other way? Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 10, 2017 Share Posted October 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted October 10, 2017 Author Share Posted October 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 11, 2017 Share Posted October 11, 2017 Have added z rotation to "A" and "D" and changed Y rotation to WORLD. https://www.babylonjs-playground.com/#RVDXB#7 If you are happy with this you can tidy it up, remove "E" and "Q" and change to mouse as you wish. Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted October 11, 2017 Author Share Posted October 11, 2017 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! Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 11, 2017 Share Posted October 11, 2017 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.