Get help using GDevApp.
User avatar
By kalel
#61111
Cesar1 wrote:Hello I would like to know how can I create radial gravity , a character moving around a planet
for example
Image


This is an interesting question! You could rotate character around a planet by simply changing the pivot point of rotation (point around which the object rotates), so instead of it rotating around its center, it would rotate around the center of the planet.

To do this, follow this thread info: viewtopic.php?f=19&t=8841

How to simulate a fully switched gravity (so you can add jump, etc) I'm not sure yet, as I haven't done this in Gdevelop. Some engines offer to change the source position of gravity.


Edit: There are "gravity coordinates" in Gdevelop, but I am not sure this is what I mean, I think it is something else.

If you check the description: http://www.wiki.compilgames.net/doku.ph ... lt_physics

It says gravity vector. A vector is basically the direction + intensity towards which the object will move. So, to make the object rotate around another object, you would need to constantly change this vector towards the center of the sphere object (e.g. when sphere is left from the object, it would be -1 0, when sphere is right from the object, it would be 1 0). Someone correct me if I misunderstood this and gravity coordinates are actually the location of gravity source. The following may not work, is completely theoretical and untested. The vector could be calculated using something like: atan2(Sphere.PointY(Centre)-Player.PointY(Centre),Sphere.PointX(Centre)-Player.PointY(Centre)) to get the angle between player and center of sphere, then using sin and cos to get the displacement (position change) vector toward that object. That would mean that movement vector should be something like
X: cos(Variable(Result))*GravityStrength
Y: sin(Variable(Result))*GravityStrength

You may need to write Y: -sin(Variable(Result))*GravityStrength because positive sin is for when Y is going up. I think Y goes down in gdevelop, so this may be needed to be inverted.

Variable result would be the result of atan2 calculation, you would save it as the value of that variable, to avoid repeating calculation or very long lines.

There might be a simpler way, but basically you would need to use physics of some type (either built in forces or physics extension), and make sure to always have a kind of "magnetic" force towards the center of the planet. Untested, but maybe "Add a force to move toward a position" with value of centre point of the sphere object, or simply add a force to move toward an object (this may use centre point already, but I'm not 100% sure).
User avatar
By sleeper_service
#61115 Assuming that the App has the same basic event functions as the desktop variant: There is a an event function for force that moves an objects towards another. As described you can have your person permanently rotate towards the planet and also continuously apply a force that has it moves towards the planet. Add a condition to only do that as long as the person is not in collision with the planet.

If you want your person to move around the planet you can add actions that have it move to the left and right (in reference to its own continuously updated angle). The object will stop colliding with the planet surface then and gravity will apply. Jumps can also implemented this way, the upwards force must exceed the planetary gravity force you apply. You'll have to play around with force amount and dampening to get all this right, but you can do all of it without much angle calculation (you don't even need the physics extension).
By Mats
#61329
Cesar1 wrote:thank you guys for your reply, I think it is more difficult than I thought


I assume it was you who asked me this on Youtube? I have looked into this and it's a very interesting problem. I shall I take a look this evening and see if I can get characters running and jumping around planets.