- Home /
Different gravity for different bodies. (2D game)
Some time ago while I was developing a top-down 2D minigolf game, I needed to implement some ramps.
In order to simulate planar physics(not sure if is the correct name), I had the global gravity set to zero, when a body was inside the ramp boundaries, I changed the gravity for that body according to the slope of the ramp. So, for instance, I could have simultaneously a body moving down the ramp while another body was moving over a flat section.
In order to do that I had to modify a couple of lines of the box2d code. I was wondering if this can be achieved in Unity, given that you can't modify the physics engine.
Just as reference, in the Bullet engine, as far as I know, this is a native feature: btRigidbody::setGravity()
Sorry for my English, I hope the question is clear.
Answer by Fattie · Oct 18, 2012 at 07:13 AM
what you need is precisely the ConstantForce component.
that is exactly how you "modify" gravity on a SPECIFIC object.
you definitely should not modify the overall gravity setting in Unity. it will lead to vast complications.
you can also simply TURN OFF gravity on an object (look at the rigidbody inspector) at timed when you don't want gravity.
Answer by mouurusai · Oct 18, 2012 at 03:14 AM
Try disable "Use gravity" in Rigidbody options and change velocity from FixedUpdate with AddForce (its may lead problem with sleeping, but i'm not sure).
Your answer
Follow this Question
Related Questions
Add Explosion Force without torque? 1 Answer
Parenting a rigid body with gravity 0 Answers
Platformer game and itween 1 Answer
Why is the sphere falling through the platform? 2 Answers
Character attract from magnet object 0 Answers