How do I get x and y speed on collision?

0 favourites
  • 5 posts
From the Asset Store
Have you ever dreamed of playing in a Speedball game or tournament?
  • I'm working with the platformer behaviour and i'm struggling to do a few things i used to do with Clickteam Fusion (still acclimatising and getting used to the differences!)

    What i'd ike to be able to do is, when the player hits a wall, a ceiling while jumping or the ground when falling (or i guess immediately as a fall ends!) is record the speed they were moving at that moment.

    My problem is, if i do this on collision, the platformer behaviour has already helpfully stopped the movement and so i can't get a speed value. And at this point, i'm stumped! Is there a solid way to record the x and y speed at which the player was moving when a collision occurs?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can get platform speed using Sprite.Platform.vectorX and Sprite.Platform.vectorY expressions.

    Save these values in a pair of instance variables at the end of every tick:

    + System: Every tick
    --> System: Wait 0 seconds
    --> Player: Set speedX to Player.Platform.VectorX
    
    + Player: On collision with Wall
    --> TextSpeed: Set text to "Collision speed:" & Player.speedX
    
    
  • Fantastic! Thank you very much dop2000, that works beautifully :^)

    Just a quick question. Can you explain the "Wait 0 seconds" part? I know it's required but just the logic is slightly lost on me.

    I was under the impression that Every tick would be all you need for something to run constantly, but i saw that taking the Wait 0 seconds out means it works if say, i'm recording the x collision while still moving (jumping and landing while moving left or right will give me the x collision vector when i land) but not if i run into a wall, where all movement stops.

    Would just be useful to fully understand.

    But yeah, great and concise answer that has saved me tearing my hair out haha! Thank you :^)

  • In Construct all events are executed one by one at the start of the tick. Wait 0 allow to delay the action until the end of the current tick.

    Another option would be putting that event at the very bottom of the event sheet. But when you have lots of interlinked event sheets, it may be tricky to figure out in what order they are executed.

  • Ahh ok, i think i understand :^)

    And yeah agreed, if it always had to come last, once a project got complicated that could be hard to manage. SP the wait 0 seconds is very handy.

    Nice one, thanks a lot dop2000

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