[SOLVED]How do I automatically switch to the closest object?

0 favourites
  • 15 posts
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • What Im trying to do is set the gravity angle of the platformer behavior to the nearest object. Kinda like a planet. So you could jump from one 'planet' to another and the gravity would switch to that one.

  • Not quite sure exactly what you want, but this may work. You could create an invisible sprite that is blanketed over your planet. If player is overlapping that object set the gravity (in the platform behavior) to a desired number. Create these blanket sprites for each planet and set gravity when overlapping them.

  • Use the pick nearest/furthest condition.

    Pick Planet nearest Player X, Player Y

    Set Player Angle of Gravity to angle(player.x,player.y,planet.x,planet.y)

    EDIT: turns out it's a bit more complex than that, to avoid getting stuck between equidistant planets. Have a look at this and see if it is what you are after.

    1drv.ms/u/s!AkmrWgxeuxlKhIdOpvGYVXnAyLV9Jw

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That is a great idea, but I found that the gravity direction breaks when you are in the middle of two planets. I think it has to do with when the other planet 'catches' you. When that happens there is a slight bounce away from the planet before you fall to it. While your example did work with the two placed there, when I tried to rearrange them to test it this happened.

  • Ok, so Ive made some changes to the original and I think it works better, but it still acts kinda weird.

    https://drive.google.com/file/d/12NVFHVP8-ovepy8CefEdjZhPevZLBx1H/view?usp=sharing

  • just an idea but maybe on planet creation you could pick all others instances and check if distance is odd or not ?

    If it's not odd, move the planet 1 pixel away or sthing like this ?

    this wont be very elegant but maybe could work ?

    this should avoid the player to be in equal distance from both

  • just an idea but maybe on planet creation you could pick all others instances and check if distance is odd or not ? If it's not odd, move the planet 1 pixel away or sthing like this ?

    Im not exactly sure what you mean by this.

  • sorry i did try and it wasnt a good idea, seems pick nearest is not rounding distances values,

    BUT, i think this should do the job ?

    https://www.dropbox.com/s/jbtmqpnmzux7cou/gravity%20shift%20%28edited%29.c3p?dl=0

    ps: of course you'll need to add some kind of filtering, maybe with "jump is pointing to this planet or not" and distance between player and planet while jumping < limitAttractDistance" or whatever you want :)

  • just an idea but maybe on planet creation you could pick all others instances and check if distance is odd or not ?

    If it's not odd, move the planet 1 pixel away or sthing like this ?

    this wont be very elegant but maybe could work ?

    this should avoid the player to be in equal distance from both

    ArmonPlan You still have the possibility of the players position being halfway between because the position is stored as a decimal.

    BaconSwagg If you add a condition like Pick Top or something to force just a single instance of the planet, you won't have 2 planets gravity grab the object. The weird thing happening when the character changes gravity is caused by the residual momentum from the original jump. If you sent the VectorY to 0, it should take care of it. I modified your project: This may give you what you need.

    drive.google.com/file/d/1sEG5lyml57XqE-BMxLYOElvJ29L3d_UY/view

  • > just an idea but maybe on planet creation you could pick all others instances and check if distance is odd or not ?

    >

    > If it's not odd, move the planet 1 pixel away or sthing like this ?

    > this wont be very elegant but maybe could work ?

    >

    > this should avoid the player to be in equal distance from both

    ArmonPlan You still have the possibility of the players position being halfway between because the position is stored as a decimal.

    BaconSwagg If you add a condition like Pick Top or something to force just a single instance of the planet, you won't have 2 planets gravity grab the object. The weird thing happening when the character changes gravity is caused by the residual momentum from the original jump. If you sent the VectorY to 0, it should take care of it. I modified your project: This may give you what you need.

    https://drive.google.com/file/d/1sEG5lyml57XqE-BMxLYOElvJ29L3d_UY/view?usp=sharing

    yeah sorry, i did tried and realized that in the pick nearest action, the distance is not rounded ^^

    by my side, i tried to add a global var to it's project to store the last landed planet and add some filtering when jumping and searching the target with pick nearest x)

    hope it's not too ugly xD

  • InDWrekt

    Wow, that actually works really well. Is there any way to stop the bounce when switching gravity to a new planet? If not then thats ok, this is farther than I ever got, and with less events too!

  • InDWrekt

    Wow, that actually works really well. Is there any way to stop the bounce when switching gravity to a new planet? If not then thats ok, this is farther than I ever got, and with less events too!

    Stopping the bounce is what this is meant to do. When the player changes gravity direction, the y velocity (or bounce) is set to 0.

  • Oh, ok. It does seem to stop the bounce when jumping straight at the other planet, but when jumping and moving it doesnt.

    [EDIT]

    I just added platform: set vector X to 0, and that seems to have fixed it.

  • I see. So, what you are referring to a bounce is actually the player changing the direction of movement. Flipping the players gravity also causes the movement direction to flip creating that sort of bounce.

    Good luck with your project.

  • The bounce is due to the platformer behaviour continuing the jump action.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)