Jump to content

RigidBody Vehicle - How to prevent flip


pevecyan
 Share

Recommended Posts

Hi @pevecyan, welcome to the forum!

   Can you put a simple version of your car... into a playground scene?

The chassis of your car has a physics "body", sometimes called a rigid body.  Here is the CannonJS API for its physics body.  There are two properties of interest, there... angularVelocity and angularDamping.  Raanan re-worked the BJS interface to the 3rd-party CannonJS and OimoJS engines... and added a feature called native parameters.  You can see some native parameters being set on a joint... in this Oimo demo - lines 87-92.

BUT, I have only seen native parameters set on joints, as seen in the above demo.  I have never seen native parameters set during a physics body declaration.

IF setting native parameters during an impostor construction IS POSSIBLE AT ALL... it might look like this:

	var chassisBody = chassis.setPhysicsState({
		impostor: BABYLON.PhysicsEngine.BoxImpostor,
		mass: 1,
		friction: .01,
		restitution: .1,

		nativeParams: {
    		     angularDamping: 0.01,
		}
	});

See "Update" below.

I would say... try increasing the angularDamping value.  Although I have not researched that property name, it MIGHT mean... "resistance to rotation".  Rotation is what is happening to your car chassis... which allows it to flip.  So, increase the damping, and the chassis might resist rollover.

Another idea:  Inside the render loop of your scene, continuously "watch" or monitor the chassis physics body .angularVelocity.  Adjust as necessary.  In fact, you may wish to simply set the chassisBody .angularVelocity to vec3  0,0,0... on every frame (every render-loop run).  But this might kill any realistic chassis leaning. 

Note:  You MIGHT need to create a Cannon-based vector3, using THAT to set angularVelocity, and NOT use a BABYLON.Vector3.  Hope this helps.  Raanan may visit soon.

Update: I finally DID see some "native options" set in a non-joint impostor constructor... in lines 68 and 70 here.  Notice they are called nativeOptions and not nativeParams.  Interesting!  Our new physics interface has SO MUCH POWER... it's just great!

Link to comment
Share on other sites

Oh, hi!

Your PM actually forced me back to the forum (calling me Jesus did the trick. I have the beard, but even after trying really hard, I couldn't convert water to wine.).

As I said in my PM answer, this is very use-case dependent. Adding more mass, especially to the wheels, usually does the trick, but it might not be the behavior you are looking for.

A demo would be awesome :) 

Link to comment
Share on other sites

Just for fun, I tried the nativeOptions { angularDamping: 1 } in line 41/42 of this car demo.

It works fine!  Car will not tip over!  It also won't steer.  :)

We need angularDamping ONLY on a single axis, probably Z.  Not gonna do, unless we do it manually, inside the render loop.  :)

Speaking of which:  http://playground.babylonjs.com/#19R0VL#2   

In that PG, lines 194-198, I tried to constantly force the angularVelocity.z to 0.  That doesn't work, either.  But I should probably be using quaternions... as described in our plugin docs.  I am not yet sure HOW to null-out the Z-only value of a quaternion, though.

I have no more demented ideas for this one.  :)  (thank goodness)  (Wingnut asks Jesus for ID)  heh

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