Change object that the player is attached to

Im using the object gravity example that has a player circling a circle physics object. How can I make a second planet object and have the player jump to (and attach) to that one. In my attempt the player continually circles the original planet. Pictured below

1 Like

Make it the same way you did with the first planet.

Depending on your gravity settings, you can have the physics behavior enabled for both planets, or you might need to disable/enable the behavior of each planet, as needed.

But we can’t give accurate help without seeing your events.

1 Like

sure, no problem:

the first condition in the picture sets the variable to 1, so that the orange planet is active (“v” is pressed). when it’s zero, the purple planet is active (“t” is pressed). the bottom condition makes it so that the spaceguy is attached to the orange planet if the planetActive variable is one. but for some reason, the spaceguy never attaches to the purple planet.

You used quotes for the t key condition.

Aside from that, have you tried disabling the last event? I wonder if it’s conflicting.
And are you moving Spaceguy towards the other planet? Gravity may not work from afar.

1 Like

ah, i see. i’ll change it to a regular keypress.
how would i go about disabling the last condition? that’s the one that allows the player to cling to the orange planet.

Just right-click on it and “Toggle disabled”. :slight_smile:

the character floats aimlessly in space when the last event is disabled.

Create a couple of variables:

GravityX and GravityY

At the beginning of the scene make GravityX equal to Planet.PointX (“Center”) and GravityY equal to Planet.PointY (“Center”). Also, repeat this process every time you activate the first planet. When you activate the second planet make GravityX equal to Planet2.PointX (“Center”) and GravityY equal to Planet2.PointY (“Center”). If you add more planets do the same for each one.

Use GravityX and GravityY in the action that applies gravity.

1 Like

thank you. one note though; it doesn’t allow me to use variables as a force to apply the Spaceguy towards. It asks me to enter a number.

Consult the wiki about how to use the variables :wink: