Jump to content

Turn off or change gravity for individual objects?


Azariel
 Share

Recommended Posts

I was wondering if there was a way to change or turn off the gravitational forces applied to a specific object. Right now my janky solution is to change the object's mass, but when setting it to 0 it appears that collision detection no longer works (at least when both objects involved in a collision have 0 mass). Are there any better solutions out there?

Link to comment
Share on other sites

This is tricky as the physics simulation is a whole system where all the actors live according to the same rules.

So changing gravity only for a specific object is kind of unsupported.

 

can you tell us what you try to achieve?

Link to comment
Share on other sites

Hi guys.  Sorry to interrupt.  Testing playground:  https://www.babylonjs-playground.com/#15EUZJ#12

Ok, for THAT PG, line 70 is an "anti-gravity engine" for red sphere1. 

Lines 54-57 add mass to gray sphere2... after 8 seconds.

*shrug*  Red sphere CAN still have impact and recoil (restitution)... but Y-axis gravity-pull, is nulled/counter-acted.

 

On 9/15/2018 at 1:00 PM, Azariel said:

at least when both objects involved in a collision have 0 mass

Yep, this is true.  https://www.babylonjs-playground.com/#15EUZJ#15

In #15 PG...
- I have set a TINY amount of mass on red sphere (line 32).  I think it automatically rounds-up to .01 mass, so the line 72 anti-gravity line is still needed.  
- The gray sphere2 has no mass.  So, I must "pull" the gray sphere2 downward (to test collision with red sphere1).  Lines 73/74 do that.

Collision works, restitution/recoil works, but it HAS TO HAVE line 32 mass.  Remove line 32, activate line 31, and re-run... to test.

hmm.  Yep, when both physicsBody's have 0 mass... no colliding done.  Darn. 

Ok, now we got a playground for the forum's mad scientists to experiment-with. 

I think the direction of study will be... trying to teach the physics engine to ignore gravity on a "custom physicsBody". 

We will probably need to overload the Cannon "body" object with a boolean like ".ignoreGravity", and then teach Cannon how to watch-for bodies with .ignoreGravity = true, and then do special no-gravity processing for those collisions.  Erf.  Rough.  hmm. 

This would be a for-one-project hack, and not a core-level thing (unless you/we can convince @schteppe into supporting such a thing... in core CannonJS future versions).   Anyway, sorry for the interrupt.  Continuing with...

On 9/17/2018 at 10:58 AM, Deltakosh said:

can you tell us what you try to achieve?

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