Sign in to follow this  

Turn off or change gravity for individual objects?

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?

Share this post

Link to post
Share on other sites

Hi guys.  Sorry to interrupt.  Testing playground:

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.

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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.