Interpolate To Fixed Position?

bsumpterbsumpter Member Posts: 9
edited November -1 in Working with GS (Mac)
Hello all.

I have a question concerning interpolate - specifically using interpolate to move an actor to a fixed position on the screen. For reference, I'm working on a side scrolling platformer based on TShirtBooth's template.

If my main actor collides with another actor (coin), I'd like that coin to fly upwards to the coin counter I have running on the non-scrollable HUD layer. I can never seem to get the coin to go to the correct HUD counter position however as the HUD is always moving with my main actor.

Any help that anyone could provide would be greatly appreciated.

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    You would need to constrain the HUD's X and Y position to global variables - e.g. HUDX and HUDY - on the HUD actor itself.

    Then, in the coin actor, use the interpolate function to move to HUDX and HUDY - these will be two separate interpolate behaviours that kick off at the same time.

    Alternatively, if you're already tracking your player's X and Y position, and your HUD is at a constant height above the player, make the coin interpolate its X position to PlayerX, and it's Y position to PlayerY + 10 (or whatever the height above the player is).

    Hope that helps!

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • bsumpterbsumpter Member Posts: 9
    Thank you, thank you, thank you QS!!!!

    Your suggestion put me on the right path and I finally figured out what I needed to do. In case others need help with something similar, here's what I ended up doing, including where I veered from your post slightly:

    1) Create the HUDX and HUDY global variables as you suggested.
    2) Double click an item on the HUD layer and unlock (creating an instance). Constrain HUDX/Y globals to the (Camera.Origin.position.X/Y + game.Counter.position.X/Y). This puts the coordinates where they should be in relation to the camera to deliver the item to the HUD counter.
    3) Interpolate just as you suggested.

    Once again, thank you so much!
  • JGary321JGary321 Member Posts: 1,246
    Just remember constraining things kills performance, so be very selective in what you constrain. I was actually doing something very similar.... this is what I did.

    Whenever coin overlaps with Hero

    If game.PlayerX > 240 then
    Interpolate self.position.x to game.PlayerX - 220 (<- this works as long as your character controls the camera & the camera is set to the smallest position so that it moves when character is at middle of screen)

    If game.PlayerX < 240 then
    Interpolate self.position.x to 20 (<--- 20 is where my "coin" icon is)

    Interpolate self.position.y to 300 (<- where my coin icon is)

    Hope this helps. This is a lot less intensive then constraining. Also for a little pizzaz, interpolate the size so it shrinks the closer it gets near the coin icon. Looks cool, it's what I'm doing.
Sign In or Register to comment.