Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprites having different physics gravity rules in same physics system?

Author
Message
pugmartin
21
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 9th Mar 2018 09:30
Hi All,

Is it possible to have some sprites act under normal gravity conditions, ie a tendancy to fall down while at the same time having other sprites act as a helium balloon and float upward?
Using the set gravity commands act on a global scale?
I cant seem to find a way to set local to a sprite its gravity settings.
pugmartin
21
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 9th Mar 2018 09:48
Hi there,

Thanks for that, I assume you mean set the mass to a negative value - however this still has the object falling under the global gravity.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 9th Mar 2018 10:16 Edited at: 9th Mar 2018 10:16
Quote: "SetSpritePhysicsMass"

I'd be horrified if that was true!

The affct of gravity on an object is unaffected by its mass in the real world so it shouldn't be in game physics either.


There is a command in Box2D for this - SetGravityScale - but it doesn't appear to have been ported over to AGK.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 10th Mar 2018 12:30 Edited at: 10th Mar 2018 12:34
Just apply a force upwards on the sprite to counteract gravity. Use SetSpritePhysicsForce()

In real life, that is all that is happening in a helium balloon - so it makes sense to copy real life in our simulations. In the case of a helium balloon it still has weight and mass and it is still affected by gravity....its just that the equivalent air volume of the balloon weighs more than the balloon and the helium in it. This is just buoyancy. Buoyancy occurs in any fluid medium (air/water). This is basic physics.

So in a simulation...Set gravity to the normal value (9.8m/s/s or whatever value you want) so normal items accelerate towards the floor. Then apply a force upwards at the sprite that you want to float. (a balloon for example)

If you apply no force...the sprite falls downwards under the force of gravity
If you apply an upwards force equal to the gravitational force (=Mass * 9.8m/s/s) then the sprite just sits there and doesn't move at all. (You are simply counteracting gravity)
If you apply a force greater than gravity...the sprite accelerates upwards. (like a Nasa rocket)

So if you open the Gravity sample that comes with app game kit, in your "Physics" directory. You can replace the code in that example with this code



It jsut adds a few forces at certain sprites

It shows some boxes which fall to the floor under the force of gravity
A box that stays still
A box that floats upwards
And a box that goes even faster upwards

Its easy really

Please note....you need to apply forces at the centre of the sprite. Specifically at the 'centre of mass' of the sprite (often abbrieviated to COM). Otherwise you cause the sprite to rotate as well.

And... you need to apply the force every frame. This is so you can control the force on a frame by frame basis. You can have cars that accelerate, turn, crash and decelerate etc...
Gravity is the only force that is applied for you by AGK....all the others are up to you....

Use the force....wisely
pugmartin
21
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 16th Mar 2018 10:37
Thanks Bengismo thats very much appreciated and sorted my problem out.

Login to post a reply

Server time is: 2024-04-19 08:03:41
Your offset time is: 2024-04-19 08:03:41