Physics Doubt :cocos2d-x

Please clarify my 4 doubts:

(1) What about setting custom gravity for separate spritesBodies. Like we can set custom gravity for particles, can we do it for spriteBody(physicsBody) too?
We can disable/enable gravity for individual objects but I want to change the values…
(2) We can create a scene implementing physics, like
auto scene = Scene::createWithPhysics();
but can we specifically create physics-layers, because this way I can specify different physics in different layers, eg- different gravity for different layers in the same scene!!
(3) Does scene gravity effects the gravity attribute in particles?
(4) What things should I take care while handling velocity for multi-resolution.

Thank You…

Hi all,
For (1) doubt I’ll be using…
virtual void applyImpulse (const Vect & impulse)
and I guess it should l help to me to achieve what I want.
I mean. since we cannot set gravity for individual physics body, so I was thinking of using a continuous force that will be applied on a body throughout as: (Gravity) - (Continuous Force)
For (2), I guess, we cannot set physics differently for all layer in the same scene. I mean all layers will have to follow what is set for their parent, i.e its Scene Node.

STILL AWAITING FOR ANSWERS OF (3) and (4) … :santa:

(1) we use applyForce for disable gravity, see PhysicsBody:: setGravityEnable(), you can apply different force to each body to simulate different gravity.
(2) see discuss: https://github.com/cocos2d/cocos2d-x/pull/5493
(3) No, particle is not a node, you can not set a physics body for a particle.
(4) The coordinate system for physics world is the same as scene, so I think you don’t need to worry about this.

  1. I use GravityScale on objects that need to respond differently
    I’m not sure if the Cocos physics body supports it (I Use Box2d directly)

  2. I don’t know - but I doubt it.

  3. No. Particles are independent

  4. Hopefully you won’t need to handle anything differently - depending on how you set up your game(!)

I model everything in the physics world then just draw the objects to present that world to the user - so I map the physics world to the screen. If you work this way there is no problem with velocity between resolutions, as the velocity of, say, 30m/s in the physics world will mean the position of a sprite will change 30 * PointsToMetersRatio each second - where PointsToMetersRatio is a value calculated when the screen resolution is detected when starting the game.

If you are just using sprites with pixel coordinates then you would need to look at handling velocities by some sort of multiplication/division factor in a similar way

e.g. if you set a sprite to have a maximum velocity of 30 pixels per second that should be multiplied by 2 for a device with twice the pixel density.

I’m sure I read somewhere about cocos being able to now use device independent positions for nodes, which would help here - but I’ve been searching for more than 20 minutes now & can’t find the reference, so maybe it was just a dream :slight_smile: hopefully someone can chime in and point us in the right direction!

haha…
You’re right… I need to multiply my velocity with my scale factory…
Thanks Buddy :smile: