# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Dark Physics & Dark A.I. & Dark Dynamix / [dark dynamix] To rotate a joined object (like a door in the hinges)

Message
Posted: 12th Nov 2012 19:36
Hi dudes, I am trying to make my airplane flaps can rotate in a virtual wing hinge.
The thing is exactly like a door!
When you open and close a door so you can see the rotation of the door in the hinges. I would to obtain exactly that!

The door is the FLAP and the wall (where the door is fitted) is the airplane wing.

I tried many way to obtain this effect.
In first I trying to simply rotate my flap but it's already joined to the wing then seems this rotation is impossible and If I force flap to rotate I get strange effects and strange forces pushing my airplane.
So probably, when an object is joined it's LOCKED.

Then I tried to make a "fly and rapid" code to delete the joint, rotate the flap and in finish remake the joint...
This work but the flap start to move far from airplane when I rotate it..
I should recalculate the flap XYZ position from the wing.. In other words this way is pure kaos for my level..

So I start to read the DarkDynamix help file in the "information" part and I see a lot of ways to join an object to another one.

I decided to try to use the "Revolute Joint function" to joint my flap in my wing..
From the picture on the DarkDynamix help file, I can see exactly a HING! and this HING is joining 2 objects (as my flap and my wing)

Test and test but just a lot of strange flap behaviours and movements... and I can't obtain nothing of good.

can you direct me in the way to use a correct way to handle my flap rotation?

Thanks
Posted: 12th Nov 2012 22:47 Edited at: 12th Nov 2012 22:57
BIG EDIT

From the following code you can obtain the flap correctly joined with 2 spherical joints in the wing (media included)

Now my BIG QUESTION IS :
How I can set the position of the flap in a precise position without getting the flap working as "wooden sign hanging on a western movie bar" ?

So probably I can set the work of the spherical hinges more or less heavy (for obtain a "slippery and fast rotation" or a "hard and slow rotation of the hinges"), and I can to set the position of the flap in permanent way too?

#### Attachments

Posted: 13th Nov 2012 00:09
Posted: 13th Nov 2012 00:16 Edited at: 13th Nov 2012 00:17
?? I think I can obtain a joined object in a precise position of the hinge run using directly the dark dynamix commands without to use EZRotate..
Posted: 13th Nov 2012 01:27
I hope so but there is a free version somewhere on these forums, maybe try that?

Posted: 13th Nov 2012 01:37 Edited at: 13th Nov 2012 01:38
Thx MrValentine for the advice and I would to try EZRotate too.. but to try to rotate a DarkDynamix physic actor, linked to another DarkDynamix shape actor (using a DarkDynamix hinge) I think I need to try to do it using the dark dynamix commands.
Also because the normal rotate and position DBPro commands did not fit when you "transform" a DBObject in a DarkDynamix object (you lost the correct position of the collision shape)

I need to stay in this way! and try to understand how I can limit rotation of my flap and how can I set it in a precise angle.

I tried with "DYN JOINT DESC SET SWING1 MOTION" , "DYN JOINT DESC SET SWING2 MOTION" and "DYN JOINT DESC SET TWIST MOTION" but I really losing my mind...
Posted: 13th Nov 2012 01:57
What you can try is, move the object with EZRotate and then when movement is complete or stopped for XXXms return it to the physics engine, but yeah I know that you can do joints in DarkPhysics so I cannot advise with DDyn as of yet...

Posted: 13th Nov 2012 10:25
I had a think for a while and couldn't think of a perfect way to simulate a hard to move flap. You could look at adding a 'drive' to the joint which tries to force it back into place, or drives it in the direction you want it to go. You could also experiment with 'materials' to see if you can add a friction component which keeps everything stiff.

However, make sure you're not over complicating things. If this flap is just there to look nice then it maybe doesn't have to be a dynamics object. You could perhaps manually make your flap and keep it out of the physics simulation all together. This will also run a lot faster than adding 2 joints and another actor to the simulation. All you need to do is:

1. Make your model so that it's hinge is on the origin (0,0,0) so that when you use rotate commands, it'll rotate around it's hinge.
2. For every game loop:
- Position it on your wing X,Y,Z coordinates (or whichever part of the plane the flap is attached to)
- Rotate Object to wing's X,Y,Z angles 'rotate object obj, object angle x(wingObj), object angle y(wingObj) etc etc.
- Now your flap it orientated to the wing's local axis and location
- Use the move object up/down/left/right to achieve local movement. So if the flap is positioned at -3,-2,4 on the wing, use the move object commands to get it there. It's now be correctly positioned on the wing.
- Use the pitch object up/down, turn object left/right, roll object left/right commands, which are like local rotations, to orient it correctly to the wing. Now your flap is correctly placed on the wing.
3. Whenever you want to open/close/animate the flap, you add an additional pitch object up command, which should rotate it correctly with regard to the wing. You can store the flap angle as a variable and pitch the object every loop by the angle the flap is open.

If I was making a physics object with several little flaps on it, which weren't important to the simulation, I would code them manually. Having lots of physics actors and joints for unimportant little doors seems a bit overkill to me.

Posted: 13th Nov 2012 11:03 Edited at: 13th Nov 2012 11:08
Hi mate!

In first please try this code (media attached):

Using this code you can obtain a flap with a UP limit and a DOWN limit too (same degrees for both).
All that using two makeJointRevolute joints (that seems to be the most appropriate way to simulate a flap)

My first objective is near to be reached.
I would just to obtain my flap UP limit is "NO DEGREES" (so as a real flap, following the wing shape) and the DOWN limit is 20° or over.
Since now the flap can rotate UP and DOWN of the same quantity of degrees.

My second objective is to obtain my flap in a stopped position, for example 20° down.

Quote: "However, make sure you're not over complicating things. If this flap is just there to look nice then it maybe doesn't have to be a dynamics object.You could perhaps manually make your flap and keep it out of the physics simulation all together. This will also run a lot faster than adding 2 joints and another actor to the simulation. All you need to do is:"

Ehh I would to follow your method but my FLAP will be a damn physical flap that will hit the air particles.. so I must to have my flap with physic

Quote: "You could look at adding a 'drive' to the joint which tries to force it back into place, or drives it in the direction you want it to go."

Ahh, this seems a very good idea! I already taken a rapid look to drive commands but not yet tested.
I am pretty certain that my 2 objectives can be reached, and I think I am not too far but damn.. already 2 full testing days and not again won the war!

#### Attachments

Posted: 13th Nov 2012 13:42
Quote: "Ehh I would to follow your method but my FLAP will be a damn physical flap that will hit the air particles.."

What do you mean by this, air particles?

I will take a look at this later today, thanks for supplying simple code example

Posted: 13th Nov 2012 14:26 Edited at: 13th Nov 2012 14:28
Dudes!! I GOT IT!!

Just adding DYN SET ROTATION command (In X axys) to my flap! And the flap will remains in the position that I have provided!

Sure this way is like a "caveman way" to do the flap movement eh..

But it's working!
So using a keyboard command I can now set my flaps position!

The interesting thing is that using the DYN SET ROTATION command I should rotate my DYN objects JUST IN THEIR LOCAL axys!.. Then I should to obtain some errors when I use this command in a joined objects (using 2 hinge joins!)
But not! The hinges taking the priority of all and when these hinges start to notice that the flap is rotating so the hinges start to work correctly and the flap is moving correctly too!

In other words I find a little "trick" to do what I wanted to do!

So Matty H, I am not longer in "urgency mode" so take really easy about before to work to find a way to make same work using and setting the joints.
(Obvious that I would to discover how to move my flaps in a HUMAN way and not in a caveman way but I repeat, I am not longer in urgency about that!
Yeah!! I am trying to make my airplane flying in a sea of air particles! (using some tricks about.. I have not a NASA computer in my home..)

And sure, Thank you all dudes!
Posted: 13th Nov 2012 16:49
EDIT:
ehhh was too good to be all true..

Now I can stop my flaps in a determinate position but when the flap is stopped by the DYN SET ROTATION (a continuous use of this command; In every cycle I call this command to make my flap remaining in the position) some forces born.. Seems that these forces are harmless but not... These forces to hamper the work of the code of the wheels

When I have the flap stopped (any angle) the frontal wheel (you can rotate this frontal gear wheel to make the airplane can go to left or right when it is on the ground) working strange..

If I want to make a U inversion of my airplane on the ground I can do this U inversion to a certain point and over this point my frontal wheel although it is still rotate (for example to left), stop to make the airplane turning.. so I obtain the frontal wheel rotate but the airplane going forward...

This probably due to the DYN SET ROTATION to a body joined via hinges to another object...
So..
I think I need to set my flaps using some "expert" way..
Posted: 13th Nov 2012 20:02 Edited at: 13th Nov 2012 20:06
Try setting the angular velocity to 0. See if that stops the flap moving. The problem is though, the angular and linear velocities are not local, and therefore if your plane is doing 1000mph and your set the flap to a linear velocity of 0, this will be pulling on the joint and stopping the plane. Setting angular velocity will probably have the same effect.

If you just had an upper and lower limit (angle) for the flaps, you could just apply a local force which always holds them at one limit. If you want varying positions for the flaps then this is much harder.

You could still use the set rotation command but you'd have to set the rotation to be local to the plane wing. So if you want to rotate your flap down 20 degrees, it'll be a 20 degree pitch rotation ON TOP OF the wing's global angle. To do that you'd either need to be good at rotational maths or use EZ Rotate:

1. Set a Euler rotation in EZ Rotate to the rotation of your planes wing
2. Pitch that angle up/down (I think EZ rotate will pitch it up/down based on where it's currently rotated (i.e. the wings rotation!))
3. Let EZ rotate calculate the new global Euler angle from this wing rotation + pitch
4. Apply that to your flap object using dark dynamix set rotation command

That may work! I think your problem with setting the rotation is that your forcing a global rotation onto an object which is attached to another one which is changing it's angle. Using EZ rotate you can calculate what the global angle should be, based on the wing angle, and apply that to the flap.

Edit: Oh, also if the flaps center of mass isn't at the hinge this will cause problems too perhaps. Maybe setup the flap so it's centre of mass is where you make your revolute joints.

Posted: 13th Nov 2012 20:54 Edited at: 13th Nov 2012 21:05
thank you mate to trying to find a solution for this problem.
I would to make my flaps position just using DarkDynamix commands (as you previously advice me using something like the DYN DRIVE commands) 'cause I have not the EZRotate plugin and 'cause I would to avoid to getting mad trying to learn something new as EZrotate when my brain is REALLY REALLY busy to handle the previously learned things about DarkDynamix And especially also it's a matter of principle!
I'm starting to love this physics engine and I really want to learn these main features! haha

I am damn near to the solution! There are a lot of DarkDynamix command to set and to handle a join so I really would to achieve to set my flap position just using DarkDynamix logic and the possibility provided by this great physic engine

Since now I am trying A LOT of (pseudo random) experiments using all the DYN commands... I think I could solve the problem, I am near but since now nothing
Posted: 13th Nov 2012 23:16
Ok last idea ....

How about setting the joint limit to 20 degrees and applying a local force to hold the flap at that angle. When you want 30 degrees for example, delete and recreate the joint with a 30 degree limit.

All out of ideas now.

Posted: 14th Nov 2012 00:38 Edited at: 14th Nov 2012 00:44
haha dude your idea is great but with some weakness!

So the force must to be always apllied on the local Y of the flaps and until the flap is in the joint limit it can't to going more down!
One of the things that worries me is the "delete and remake joint" part..

I already tested something similar with not good results (loosing XYZ coordination between flap and wing when the delete/remake joint happen)

Over that, remain that I will have to do the same thing (if this thing will work) with the tail control surfaces and could be worse than placing a flap in a preset position since the tail surfaces are always in movement when you pitch and when you are banking..

And remain too that the force I will apply to the flaps will involve the entire airplane since all airplane parts are joined togheter... .. I should to obtain an airplane getting a mysterious force in the flaps position making my airplane flying in a not real way.

mmmm
Posted: 14th Nov 2012 08:55
haha. Ok, one more solution, and this is a good one!

Just physically obstruct the flaps with an invisible dynamix object. So perhaps:
1. Create a cube or sphere (nice fast collision shape)
2. Setup collisions so it can only collide with the flap and nothing else
3. Every game loop position at the correct point for maximum flap movement using dynamix commands.
4. Apply a force to hold the flap against this invisible 'stop block'

You can position it using the same technique I've mentioned before:
1. Set stop block to flap position (db commands)
2. Set stop block to flap rotatation (db commands)
3. Move stop block up/down/left/right into correct stop position (db command)
4. Now set dark dynamics position for this block so it's in the right place for the simulation

That's gotta work.

Posted: 14th Nov 2012 10:45 Edited at: 14th Nov 2012 10:58
Ahhh really GREAT and BIG idea dude! and really could to be the good one!

Quote: "
3. Every game loop position at the correct point for maximum flap movement using dynamix commands."

Do you mean to do that using the DBpro commands ( Set stop block to flap position, Set stop block to flap rotatation, Move stop block up/down/left/right into correct stop position ) instead dark dynamix command!? right?

Quote: "4. Apply a force to hold the flap against this invisible 'stop block'"

Maybe we can avoid to use external forces (always a bad thing to have a hidden force pushing somewhere on a flying airplane! )
and to use a reverse STOP BLOCK to use with the first STOP BLOCK!

And at this point I need to join these blocks to my airplane making these block mantaining their XYZ coordination with flap and airplane.. right?
Look at attached pic!

#### Attachments

Posted: 14th Nov 2012 13:21
How you do it exactly may require some experimentation (as usual with physx!).

You could move the stop blocks to move the flap, but using a force would work too. If the flap's mass compared to the rest of the plane is very low, then applying a force to move it shouldn't affect the plane. Plus, this is what would happen in the real world. The flap would be driven by an electric motor (or hydraulics perhaps) and the act of turning that motor would exert force on the plane wings in strange directions. It's just because the force is so slight in comparison to the plane's mass that it has no effect. So I wouldn't be scared of applying a small force. It could work!

As for positioning the stop block, the final position of the stop block will have to be set with the dynamix command. Otherwise the physics simulation won't know where the stop block is! But to work out the position to place the stop block would be easiest using dbpro commands. Then once it is correctly positioning with dbpro commands, set it to the same position with the dynamic 'set position' command. Moving the visible DBpro object about has no affect on the physics simulation. Dynamix will just put it back to the physics position next time it updates.

So I would:
1. With dbpro commands:
- Set object position stop block or sphere at flap hinge position. Hopefully you can get the flap hinge position from the flap object itself.
- Rotate object stop block to match the WING rotation, so the stop block is facing down the wing.
- pitch object up the stop block to the desired angle
- move object the stop block backwards into position so it's blocking the flap
2. Save the coordinates for the stop block
3. dyn set position (or whatever the command is, I forget!) the dynamix actor to this saved coordinate
4. Done!

Moving the block around like that will have no affect on the simulation because dark dynamix doesn't care about what you do with models. It'll just position them back where it expects them to be next time you call simulate.

Posted: 14th Nov 2012 15:26
Fallout your method start really to convince me that it's perfect!

All morning trying again and again to edit the "makeJointRevolute function" to obtain some decent results but believe me... All I got is pure frustration.

Your method seems really going not to "rape" (haha) the flight dynamic of my airplane and since now it seems really going to work fine as a physical flap mechanism!

Really a huge thank you for total support and help Fallout!
You really holding on without surrender for my project!

Test time now and please wait for the update!
Posted: 14th Nov 2012 18:06
I like these sort of discussions mate. Rather than having to write a load of code to help someone I can just think about physics, come up with an idea, then send you off to test it! haha. I'm learning as much as you without having to do any coding myself!

Posted: 15th Nov 2012 11:51 Edited at: 15th Nov 2012 12:10
Hi again Fallout and hi to all too.

I made a first version of flap code just using the Fallout advices!

For now I reach to make a 2 flaps position:
NO FLAPS
FULL FLAPS

I make the flap joined with 2 hinges to the wing and I apply a force that make the flaps going UP or DOWN.
If "NO FLAPS" configuration is choosed so a downward force pushing up the flap since the flap touching an hard iron piece (with a big density) that stop the flap up motion.

If "FULL FLAPS" configuration is choosed so a upward force pushing down the flap since the flap reach the HINGE DOWN LIMIT.

This HINGE DOWN LIMIT (as the HINGE UP LIMIT) is edited using this code on the makeJointRevolute function:

The force I am using to move the flap is:

I am very happy about finally I reach to make this 'cause I burn a lot of time trying to set the hinges using DYN DRIVE commands and never I Obtained something good but just NO RESULTS.

TO Fallout:
Mate, I am trying to make what you wrote about the "mechanism" we have to use to set the flap position but I realized I did not understand well what you mean..

I understand you want to "move" a object (this object MUST be coordinate with the airplane coordinates so we must to join it to the main airplane body) that with its movement start to push the flap making the flap straightening (with the downward force always pushing the flap to this object) If we are in the case we want to pull up the flap.

But I am really in difficulty to MOVE a joined object 'cause this object will start to lost coordination with the main airplane body when I delete the joint. (I must to delete the joint If I want to rotate a joined object)

You wrote this procedure 2 times with some differences and I lost the comapss about..

Believe me, I'm really beyond my brain capacity to handle all that... I back to programming after some years of ZERO programmations and I am not too young to handle easly these damn complex matters. I am telling that just to make you not angry 'cause I am trying to ask you If you can explain again your procedure about this "flap moving mechanism"!

however today a great win and I hope you and all can try the attached program.
It's just a first step (but working fine ) to make a joined parts (joined via hinges) moving with a precise command!
And your method is the ONLY ONE is working since now to obtain a moving flap.

#### Attachments

Posted: 15th Nov 2012 14:26 Edited at: 15th Nov 2012 14:30
No problem! My thought was that the 'stop block' should not be joined to the plane. If it is positioned every single loop, it probably doesn't have to be attached to the plane. I would do this:

1. Make a sphere object in DBP
2. Make a dyn sphere from it. You could use a cube but a sphere won't have any sharp edges plus a sphere is probably faster to simulate in phyx.
3. Hide the DBP sphere. Now it's invisible but still in the physics simulation.
4. Dont attach it to the plane with a joint. There's no need!
5. Every loop:
- Using DBP commands, position the hidden sphere at revolute joint which connects the flap to the wing. The easiest way to do this is model your flap object so that the origin of the flap object is where the hinge will be. Set it up this way in your modelling program. Now you can: position object objStopSphere, object position x(flap), object position y(flap), object position z(flap) and the stop sphere is positioned at the joint!
- Rotate the DBP object to the same orientation of the wing. So rotate object objStopSphere, object angle x(wing), object angle y(wing), object angle z(wing). The dbp sphere is now positioned at the hinge and looking down the wing.
- Use pitch object up objStopSphere to rotate the stop sphere to the desired flap angle. This pitching will be a local rotation for the sphere and will act ON TOP of the current rotation. So the sphere is facing down the wing and will then look up or down locally.
- Use move object objStopSphere using a negative value. This will move the stop sphere backwards in the directions it's facing, so towards the tip of the flap. Move it about half the depth of the flap so the flap will touch it.
- The stop sphere DBP object is now in position to stop the flap, but the dark dynamix sphere is not! So now dyn set position objStopSphere, object position x(objStopSphere), object position y(objStopSphere), object position z(objStopSphere). This will now postion the dynamix sphere at the position you've worked out using the dbp sphere.
- Repeat this procedure EVERY game loop. This will keep the 'stop sphere' in the right place.

Now you can apply your local forces to push the flap against the stop sphere.

To make this more reliable, you could dyn set kinematic the stop sphere. This stops any other object from moving this sphere and stops gravity affecting it. It basically can only be moved by you!

The only problem I can foresee is that the simulation may move the flap before it repositions the stop sphere. It may not work but you won't know until you try!

Posted: 15th Nov 2012 17:54 Edited at: 15th Nov 2012 17:56
Mate I done a first version of your flap mechanism and start to work!

There is just a little problem (I hope it's little!). As your words:
Quote: "The only problem I can foresee is that the simulation may move the flap before it repositions the stop sphere. It may not work but you won't know until you try! "

Maybe you mean exactly that. Seems is there some strange fail coordination between the DBPro sphere and the DYN Sphere.

Please run the attached project and test it!
Using UP key you can move UP the flap and using DOWN KEY you let the flap go down. You can also see the red sphere (not again transparent)

Thanx to the DEBUG render you can easly see how the DYN Sphere lost his coordination with the DBPro Sphere.
This mean that the collision between the sphere and the flap seems not enough sincronized.

But we are really near to achieve the result!

#### Attachments

Posted: 15th Nov 2012 19:21
Interesting! Two things you could try:

Firstly, definitely try making the sphere kinematic. So after:
DYN MAKE SPHERE 9074,100.0 rem sphere block flap

DYN KINEMATIC ON 9074

This will make sure your sphere can only be positioned by you and the simulation won't move it at all (it won't spin either like it's currently doing).

If that doesn't fix it, use a different object to position the 'stop sphere'. Perhaps positioning the sphere with DBPRO commands and then positioning the SAME sphere with DYN commands IS causing problems. If it is, make an additional object which is never set as a dynamics object. Then move this one around to obtain the 'stop sphere' position, then set the stop sphere to that position. That will ensure moving the dbpro object isn't messing about with dynamix!

Posted: 15th Nov 2012 21:13 Edited at: 15th Nov 2012 21:21
Ahhhh mate!!! it's work GREAT!

Just adding the DYN KINEMATIC ON 9074 command as you advice and the flap mechanism WORKING PERFECTLY!!

Now I can move all my airplane surfaces without problems!

I am out of words to tell you THANK YOU mate! Your method is the right way to enter in the DarkDynamix physic world:
To use forces to move all! From mechanisms to wheels, from air particles to a flag pushed by the wind! Without strange "against physic world" tricks.

I needed just a mechanism to move my flaps

Thanks to your help, I have overcome a problem that prevented me to continue my project!

Posted: 15th Nov 2012 21:57
Really good to know! Well done and I'm glad to help. Hopefully the mechanism will still work when the plane is moving along at speed. You'll find out when you start flying!

Once you get a bit further on and are flying your plane, make sure you start a thread in the Work In Progress forum so we can see the game progress.

Posted: 16th Nov 2012 02:54
Yeah mate