How do I get the speed of an object using the Sine Behaviour for Moving Platforms?

0 favourites
  • 8 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • Previously we have been using the Bullet Mechanic for floating & moving platforms for a top down RPG and these seem to work fine however, every once in a while they just ignore their rules and disappear off into the ether.

    So I'm thinking about using the Sine Behaviour as a replacement as it's 100% reliable in its movements.

    However, previously we were using this to move the player left & right on a moving platform (that had the bullet behaviour)


    Which works fine, but there seems to be nothing similar to Bullet.Speed that I can use from the Sine Behaviour?

    Thank you in advance.

  • It's easy to calculate platform speed from its position in a previous tick. Add two instance variables - previousX and speed:

    On every tick:
     Platform set speed to (self.x-self.previousX)/dt
     Platform set previousX to self.x

    You can actually just add the distance platform traveled since the last tick:


  • Thank you so much dop2000, that's so brilliantly simple. You're a genius!

    One final question,

    So when the Player is overlapping the Platform (it's a top down RPG) how do I get the player to move in time with the platform?

    I've tried this (and a few others) to no avail


  • Could you share a sample project?

  • or just set the player to the platform x that it is overlapping

  • Thank you both for replying AllanR and dop2000

    Unfortunately I can't share a project, as it's almost a full game.

    The code looks like this ...

    However, when the player object stands on the platform_moving_small object, the player doesn't move with the platform. Very odd.

    If I change the movement of player X to look like this

    The player moves fine (as 47 is the Platform_Moving_Small.Speed instance variable)

    But this leaves us with only ever having one speed for platforms. So how can I use the speed instance variable with this Set X ?

  • Figured it out, but wanted to post so any people trying this could find the answer easily.

    So when the platform was moving to the left, the Platform_Moving_Small instance variable was -47 ... essentially this was making the player object move in the opposite way so I used ABS to turn it into a positive number and boom it works.

    The event looks like this ...

    + Platform_Moving_Small: Speed < 0

    -> Player: Set X to Self.X-(dt×(abs(Platform_Moving_Small.Speed)))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What behavior are you using for the player? An object with Platform behavior can stand and walk on moving platforms, you don't have to do anything.

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