Jump to content

Helicopter wiggling Babylon Cannon


wo997
 Share

Recommended Posts

Howdy, I'm working on helicopter simulator in babylon.js using cannon.js. I managed to create auto-stabilizing system and put some controls, air friction is done temporarily, but it's not the problem. Just try it (dowload zip file) and see that it's not working propertly, pink sphere shows center of the airscrew and is not a physics object. I thought it's ok, because it's how gyroscope works, but then I made the airscrew a square (commented part in source code) and it stopped wiggling. There may be a few reasons why is that and at this moment I'm not sure if it's physics misconception or it's a problem with cannon.js. To play the simulator press arrows to tilt, w/s to fly up/down, a/d to turn.

3d gem - Kopia.zip

Link to comment
Share on other sites

Hiya wo997... welcome to the forum.  Your heli is SO COOL!  I LOVE IT!

Into the playground we go.  I hope you don't mind.  http://playground.babylonjs.com/#11OMIX

Couple broken textures... no biggie.  I turned-off shadows and particles for now.  Changed your functions a bit, scope-wise.  Modded the keypress listeners a bit.

Line 54 is causing the sphere wiggle. 

I'm not sure if this is pertinent, but physics joints seem to have "wobble".  http://playground.babylonjs.com/#1ND6TH#5  Click on screen to see EXTREME joint wobble.  Not sure if anyone has been successful at tightening the bearings, yet.  :)

*shrug*.  I haven't studied HOW you derive pos3 (line 54)... but now that we have it in playground mode, more eyes can see it easier.  Perhaps more comments/help, too.

It's pretty fun to fly!  Congrats on this thing... it's niiiiiiice!

Link to comment
Share on other sites

Nod.  You could constantly null-out the angularVelocity on the main rotor shaft... in the render loop.  That main rotor shaft is tilting side-to-side, due to micro-inaccuracies of rotorblade centrifugal forces (it needs automobile wheel weights... tire balancing).  :D

But... main rotor shaft tilt... is needed, for control.  So... hmm.  At best, you could get the shaft to stop tilting... when dead-stick (centered)... but no forcing during flight.  Wow.  Cool challenge.  I love heli's.

I wonder.  hmm.  If you put invisible physics-active rotor blades... (or simple boxes with SOME mass)... in-between each visible blade... hmm.

Link to comment
Share on other sites

On 1/12/2017 at 12:44 PM, Wingnut said:

Nod.  You could constantly null-out the angularVelocity on the main rotor shaft... in the render loop.  That main rotor shaft is tilting side-to-side, due to micro-inaccuracies of rotorblade centrifugal forces (it needs automobile wheel weights... tire balancing).  :D

But... main rotor shaft tilt... is needed, for control.  So... hmm.  At best, you could get the shaft to stop tilting... when dead-stick (centered)... but no forcing during flight.  Wow.  Cool challenge.  I love heli's.

I wonder.  hmm.  If you put invisible physics-active rotor blades... (or simple boxes with SOME mass)... in-between each visible blade... hmm.

I did it! Here is the final result:

http://playground.babylonjs.com/#11OMIX#3

I had to push the helicpoter upwards instead of airscrew - it's not done how it is in reality, but it's still pretty ok. I just have to remember I can't add forces to fast rotating elements.

 

Now I want to improve it by adding better helicopter graphics and also physics body, do you think you can help me with that? I'm still poorly experienced ;)

Link to comment
Share on other sites

Hey, congrats, nicely done, wo!  I can "steer" you a little toward some ideas, but also... the step-by-step "struggle" of improving the heli graphics and physics... is REALLY REALLY fun.  It feels a little painful while doing it, but afterwards... it feels REAL GOOD.  I would not want to take away any fun from you.  Plus, I'm really not very experienced at modeling or physics coding.  I'm best at talking incessantly.  :D

That said (and so much more saying to come)... I want to show you my bobsled.  I'm proud of it.  It is modeled with math and parametric shapes (ribbons, extrudes, tubes, thanks Jerome and other vertexData code/brains contributors).  It has some mis-aligned lighting normals on the nose and cockpit ring-segments, but it still rocks!  Math made.  (control-drag to adjust arcCam target)  (borrow code/techniques freely)

I :wub:LOVE:wub: mesh models that are dynamic (created on the fly).  But, it's fun to grab Blender and have some fun there, too.  Import a model, slap-on Cannon meshImposter, and see what happens.  That's fun, too.  There's also... "the big invisible box" method of adding physics to the entire heli-body.  But, that won't give you collision precision... when you accidentally swing the tail boom into a telephone pole.  :)  The collision will happen early, because the "big box" imposter will hit the pole... BEFORE the actual narrower-than-crew-cab tail boom mesh... hits.

The Cannon meshImposter won't have that collision inaccuracy.  It will match the contours of the helicopter body.  BUT... keep the mesh lower rez... for maximum physics speeds.

Notice my bobsled has lots of curved surfaces.  This might not be "optimal" for Cannon meshImpostor.  You might consider modeling your heli body... like this, because... 1. It looks cool.  2. It has radar-absorbing flat surfaces.  Flat surfaces = reduced vert-counts for your model, and faster physics for the meshImposter.

You might consider grabbing a ZIP of that playground, taking it home, and continue dev from that new index.html... for now.  That way you can paste the big createScene() function into the playground... easily and anytime.  Just keep your dev following the "format" that comes in the index.html file from the ZIP.  Later, you can adjust to different formats (like separated files and more OOP structures).  For now, having that easy-paste to the playground... will help others help you with future issues.

How's that for a little bucket of thoughts?  It might give you some things to think about.  :)  Are you welcoming comments from others, too?  There's some talented game/sim coders nearby... more talented than I.  But, most of them can't TALK as much as I can.  heh

Link to comment
Share on other sites

On 1/13/2017 at 10:35 AM, Wingnut said:

Hey, congrats, nicely done, wo!  I can "steer" you a little toward some ideas, but also... the step-by-step "struggle" of improving the heli graphics and physics... is REALLY REALLY fun.  It feels a little painful while doing it, but afterwards... it feels REAL GOOD.  I would not want to take away any fun from you.  Plus, I'm really not very experienced at modeling or physics coding.  I'm best at talking incessantly.  :D

That said (and so much more saying to come)... I want to show you my bobsled.  I'm proud of it.  It is modeled with math and parametric shapes (ribbons, extrudes, tubes, thanks Jerome and other vertexData code/brains contributors).  It has some mis-aligned lighting normals on the nose and cockpit ring-segments, but it still rocks!  Math made.  (control-drag to adjust arcCam target)  (borrow code/techniques freely)

I :wub:LOVE:wub: mesh models that are dynamic (created on the fly).  But, it's fun to grab Blender and have some fun there, too.  Import a model, slap-on Cannon meshImposter, and see what happens.  That's fun, too.  There's also... "the big invisible box" method of adding physics to the entire heli-body.  But, that won't give you collision precision... when you accidentally swing the tail boom into a telephone pole.  :)  The collision will happen early, because the "big box" imposter will hit the pole... BEFORE the actual narrower-than-crew-cab tail boom mesh... hits.

The Cannon meshImposter won't have that collision inaccuracy.  It will match the contours of the helicopter body.  BUT... keep the mesh lower rez... for maximum physics speeds.

Notice my bobsled has lots of curved surfaces.  This might not be "optimal" for Cannon meshImpostor.  You might consider modeling your heli body... like this, because... 1. It looks cool.  2. It has radar-absorbing flat surfaces.  Flat surfaces = reduced vert-counts for your model, and faster physics for the meshImposter.

You might consider grabbing a ZIP of that playground, taking it home, and continue dev from that new index.html... for now.  That way you can paste the big createScene() function into the playground... easily and anytime.  Just keep your dev following the "format" that comes in the index.html file from the ZIP.  Later, you can adjust to different formats (like separated files and more OOP structures).  For now, having that easy-paste to the playground... will help others help you with future issues.

How's that for a little bucket of thoughts?  It might give you some things to think about.  :)  Are you welcoming comments from others, too?  There's some talented game/sim coders nearby... more talented than I.  But, most of them can't TALK as much as I can.  heh

Thanks for advices, I appreciate it. Yeah, I will make it quite minimalistic, I like to make things like that. Just a quick question - how will the cannon js make physics impostors for more advanced meshes? Will that happen autimatically? I hope so... I defninitely need to spend some time searching things you mentioned, that will take a few hours, wondering if I should add emoticon or not... :) I did.

Link to comment
Share on other sites

haha.  Yep.  Yeah, you just choose meshImpostor instead of boxImpostor or sphereImpostor, etc.  It's easy.  http://doc.babylonjs.com/playground?q=meshImpostor

183 playgrounds that use meshImposter.  And only CannonJS allows it, so you don't have to worry about OimoJS playgrounds getting in your way of touring. 

Notice I have been mis-spelling impostor.  I accidentally spell it 'imposter' sometimes, sorry.

What plan did you have for the particles?  (if you don't mind me asking)   Are you going to attempt swirls/vortices... under the main rotors... when landing/departing on sand/snow?

That would be something, eh?  Perhaps make it optional, for those who are "into" making swirls instead of hauling cargo/passengers.  :)

Link to comment
Share on other sites

On 13.01.2017 at 6:42 PM, Wingnut said:

haha.  Yep.  Yeah, you just choose meshImpostor instead of boxImpostor or sphereImpostor, etc.  It's easy.  http://doc.babylonjs.com/playground?q=meshImpostor

183 playgrounds that use meshImposter.  And only CannonJS allows it, so you don't have to worry about OimoJS playgrounds getting in your way of touring. 

Notice I have been mis-spelling impostor.  I accidentally spell it 'imposter' sometimes, sorry.

What plan did you have for the particles?  (if you don't mind me asking)   Are you going to attempt swirls/vortices... under the main rotors... when landing/departing on sand/snow?

That would be something, eh?  Perhaps make it optional, for those who are "into" making swirls instead of hauling cargo/passengers.  :)

Hmmm... it doesn't seem to be that easy at all, I tried:

mesh2.physicsImpostor = new BABYLON.PhysicsImpostor(mesh2, BABYLON.PhysicsImpostor.MeshImpostor, { mass: 1, restitution: 0.9 }, scene);
mesh2.checkCollisions = true;

and

var mesh2Body = mesh2.setPhysicsState({ impostor: BABYLON.PhysicsEngine.MeshImpostor, mass: 1, restitution: 0.8, resistance: 0.9 });
mesh2.checkCollisions = true;

but it just falls through the ground, I created a ribbon shape.

Link to comment
Share on other sites

Hi again!  First, that .checkCollisions thing... you don't need that for physics engine.  That is used for the lesser-powered non-physics-engine gravity/intersect system that is built-into BJS core.

Also, make sure you are using CannonJS, and not accidentally using OimoJS, which is the default 3rd party physics engine.  Use the same physics engine start-up technique (in your project)... that we used in the playground demos.

Ready for the worst news of your life?  :/

MeshImposters ONLY can collide with sphereImposters.

SO... hehe... I think your "ground" is about to become a planet... a huge sphere... with unknown amounts of subdivs/tessellation.  :)  Fun!  Good luck!  May your horse be with you!

Oh, you want to know HOW we are going to make a telephone pole out of sphereImposters... for the tail-boom to swing-around and hit?

(oops, there's my phone, I gotta get that.  I'll be back later... next month... and we'll talk more about that telephone pole.  Bye bye now.)  :D

Link to comment
Share on other sites

Oh well, so I have to create a physics body on my own, I could do it if I knew how to do basics, can you give me a link to anything? I think that about 10 cubes would be enough, but these has to be one mesh and yeah... I know there is something like merge meshes, but is that good in this situation?

Link to comment
Share on other sites

Nah, don't venture into joint-linking spheres together, yet.  That will give you a headache.  :)

Here's a question.  What are your plans?  Do you want the helicopter to eventually bounce-off-of, or rub-against ANY other scene object, and do it realistically?

I suppose, huh?  :)

BUT... if your basic game is perhaps... a simple obstacles-avoidance game (like fly between the poles, pick up cargo, return between the poles), then those obstacles COULD have easily-made jointed-together sphere-chains.  (like a pull chain on some light fixtures).  BUT, remember how you saw "joint wobble" in my train wheel demo?  These chains of spheres are a bit wobbly... so the telephone pole imposter-chain... could have some wobble.  Users won't see it (can't see imposters), but... it could "recoil" the tail boom after impact.  The telephone pole might be "springy".

But, all in all, ya gotta try replacing your ground with a HUGE sphere, and using that as your landing pad.... see what happens.  If everything is right, the heli should sit atop the surface of the planet just fine.  Its easy to try it... what the heck.  :)

http://playground.babylonjs.com/#11OMIX#4

CORS-cleared-for-reuse image of bricks... for us to temporarily use.  :)

"It flies like a ton of bricks!"  :D

Link to comment
Share on other sites

http://playground.babylonjs.com/#11OMIX#6

Here's meshImposters on everything except the sphere-based ground.

Fun!  :)  Folks might need to click on canvas ... to make cursor keys and wasd keys... work.  Good-flyin' little heli!  For those who do helicopter sims, you know what a good "feel" is like.  This one is the best I've felt in webGL, ever.  (Not like I've tried a lot of webGL heli-sims, though).  :)

This one... makes you feel like flying some "cargo hook" missions RIGHT NOW.  It feels good... I like it.

Link to comment
Share on other sites

I can't make it all with spheres, I want some buildings and there can be a way to brake a tail and stuff, I'm familiar with making body with many jointed spheres, is there a way to make spheres other shape too like stretched cubes? I hope I don't get a headache, but I must do everything I can.

Link to comment
Share on other sites

Hi again wo!  I saw you talking in the other thread.  I have a playground that uses a meshImpostor ground... and then assembles a "pad" (a platform of spheres), hard-jointed together via the old, deprecated scene.createCompoundImpostor() method.  This playground was part of the XMAS bobsled/sledding-hill adventure that we tried... for the holidays.  :)  The noise-genned ground is ready for animating, too, but I just call its animate function once... to "derive" the initial ground shape.

It doesn't work very well, physics-wise, but it might be something fun to play-with.  It also has Raanan's cloth code... remarked-out in there.  His cloth maker is likely more efficient than my nest for-looper thing.  Anyway, might be something useful.  I wonder what createCompoundImpostor DOES?  hmm.  Could it "assemble" a group of many box impostors... into the shape of a helicopter?  hmm.  :)

Link to comment
Share on other sites

I've actually solved problem with physics body for helicopter, how did I do that? Simply by creating invisible spheres and jointing them strongly using 2 hinge joints per 1 joint between main mesh and body part, all looks well, so is that what you've been warried about I can get headache? Seems to be very intuitive :) Do you want to see the little effect now or can you wait until I add some more stuff and create full graphics for heli? Now I think I will do some stuff like disabling physics for texture body and I will need more of these for different colors, then I have to set position and rotation, wow... that's a lot but I feel happy when doing this :D 

Link to comment
Share on other sites

Cool.  The headache part would come... when you decide to make the helicopter body... from 20 spheres (or more).  (such as requiring 10 spheres on every propeller blade) :o

As long a you are happy, I am happy.  :)  Just.... hurry up and give us a cargo-hook helicopter game to play!  Let's go flying!  :) 

Watch out for those evil down-drafts!  We just barely have enough lift... to lift this cargo... and we need to take it across a river, and over some trees... and around the side of a small mountain, cuz we don't have enough lift to get OVER it.  Wow!  The adventure begins!

Oh man... wind-drag on the load, too!   "Oh no!  It's flying like a ton of bricks".  Yep, that's right ladies and gentlemen.  It's Wo997's World Famous "Ton Of Bricks" Helicopter Simulator... Gold Edition!  YAY!

Link to comment
Share on other sites

On 1/17/2017 at 10:30 AM, Wingnut said:

Cool.  The headache part would come... when you decide to make the helicopter body... from 20 spheres (or more).  (such as requiring 10 spheres on every propeller blade) :o

As long a you are happy, I am happy.  :)  Just.... hurry up and give us a cargo-hook helicopter game to play!  Let's go flying!  :) 

Watch out for those evil down-drafts!  We just barely have enough lift... to lift this cargo... and we need to take it across a river, and over some trees... and around the side of a small mountain, cuz we don't have enough lift to get OVER it.  Wow!  The adventure begins!

Oh man... wind-drag on the load, too!   "Oh no!  It's flying like a ton of bricks".  Yep, that's right ladies and gentlemen.  It's Wo997's World Famous "Ton Of Bricks" Helicopter Simulator... Gold Edition!  YAY!

I did it!!! :D:D:D 

http://playground.babylonjs.com/#11OMIX#19

Just to make sure, WASD and Arrows, have fun!

Link to comment
Share on other sites

Oh yeah!  It bangs off the wall real good.  I managed to land it atop the wall, butt-first.  :)  The tail rotor is on one side of the wall, the skids on the other, and the heli is looking almost straight up.  The tail rotor is whackin' on the wall, making everything shake.  Too good.  ALL the small animals have run and hidden.  I wonder if it will fly out of this situation.  :)  Congrats on the decent impostoring!

Link to comment
Share on other sites

On 19.01.2017 at 7:20 PM, Wingnut said:

Oh yeah!  It bangs off the wall real good.  I managed to land it atop the wall, butt-first.  :)  The tail rotor is on one side of the wall, the skids on the other, and the heli is looking almost straight up.  The tail rotor is whackin' on the wall, making everything shake.  Too good.  ALL the small animals have run and hidden.  I wonder if it will fly out of this situation.  :)  Congrats on the decent impostoring!

I've been looking for a way to remove constraints here https://doc.babylonjs.com/classes/2.5/PhysicsImpostor but I can only see how to create/add them. Is it even possible to remove constraints? I wanted to make it so when force is way to high it just crashes, but I can't figure it out.

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...