Orientation in flight / 3d space
Hi guys! I'm having somewhat of an issue :-) I have built a flight model which includes lift, thrust, drag mechanics - one of these elements detects the angle of attack (ie the angle of the plane pointing up or down) and recalculates what the top speed should be versus the current speed and accelerates up or down accordingly. As an example, the top speed in level flight is 140 m/s, the top speed in a vertical dive is 250 m/s and the top speed in a vertical climb is 0 m/s, with a n automatic calculation for every angle inbetween. If you are travelling at 140 m/s and dive, the logic accelerates towards the new top speed. Once you level out, the effective top speed lowers due to drag and the plane accelerates again. This is being calculated via an angle sensor on the plane attached to a splitter.
This all works well when travelling in a straight line, however as soon as you change the rotation on the other axis, the vertical angle goes wonky. If for example you turn the plane 90 degrees clockwise, and then climb, the vertical angle doesn't read correctly at all.
I've read another topic which talked about euler angles, and I will have a read up, but does anybody have any ideas at all?
-
Hi,
the most robust solution is probably to use a bit of vector maths.
First thing you need is a vector that points along the direction of your aircraft's nose. You can get this by placing a movement sensor on the aircraft, set "Local Space" on, and align the X Direction (the white arrow with X on it) along the aircraft's nose.
Next thing you want to do is a "Vector Dot Product" with a vector that represents the direction of gravity. This will essentially get you a number that is 1 when the nose points directly down, -1 when the nose points directly up and 0 when the nose is level with the horizon. Luckily the dot product in this special case is simply the Y component of the aircraft nose vector multiplied by -1. So you just need to add a splitter to the X Direction output of the movement sensor, take the Y component from the splitter and multiply it by -1. Obviously you can forgo the multiply by -1 and just take into account the result will be inverted.
Hope that helps
Matt -
Hi Matt
Thanks very much for the prompt reply! I thought it had cracked it, as upon first testing it works exactly as intended. However, as soon as you alter the course from straight ahead, the numbers go crazy exactly the same as my attempt with the angle sensor. If you turn 180 degrees, the numbers are flipped, if you turn anywhere in between I cant figure out the pattern but they go crazy. Anything other than straight on and even the roll of the aircraft affects the number even if the X direction remains the same.
Anything you can do to help would be massively appreciated! -
I've messed around some more to figure out what's going on - the axis are staying fixed to the world even with local space turned on. I've tried all three axis and get the same result.
In the case of X pointing straight ahead, initially the pitch rotates about the Z axis and the split 3 value from X starts at 1 and changes between -1 and 1, as well as the split B value from Y which starts from 0. If you rotate the heading by 90 degrees, the split B value from X starts at -1 and changes between -1 and 1, as well as the split 3 value from Y which starts at 0.
Basically, none of the axis follow the plane, so the outputs change depending on which direction the aircraft is facing. -
Hi, if you're not seeing the axes follow the plane then it sounds like the movement sensor is not attached to the thing you think it is. Try placing it directly on a part of the aircraft model rather than on a group. Remember that if you make a model or group moveable (or place a mover/rotator on them) then they will no longer move with the parent group.
-
Will try this later thanks very much sir! Fingers crossed :-)
-
No luck I'm afraid... :-( to make sure I wasn't doing anything wrong I started a new scene, created a single block, added the movement sensor directly to it and then fed the outputs to a microchip with the splitters. Exactly the same problem with different values changing depending on the direction the block is facing. I'm very stuck!
-
I should add, the axis themselves from the movement sensor follow the object but the x y and z values switch around depending on the direction. It's like the x y and z values are tied the the world, so whichever axis from the sensor aligns, this is the one which changes the dot vector product value.
-
I'm at a loss :-(
-
SUCCESS!!!!! I cant tell you how happy I am! I completely overlooked the greyed out outputs on the splitters. I had assumed only the two lit ones did anything but upon randomly linking B to a calculator the magic happened :-) thanks for your help Matt!
댓글을 남기려면 로그인하세요.