How to trigger an event based on the travelled distance of an object

From the Asset Store
112 High-Quality destruction sounds for videogames
  • Hi Guys,

    I'm making and endless falling game and i'd like to trigger an event each time an object has traveled X distance. For example I'd like to trigger and event when the object has fell a distance of 1000. So an event is triggered when the object reaches the Y coordinate of 1000,2000,3000 etc.

    Any help would be greatly appreciated. :)

    Thanks

  • You add a variable "yLimit = 1000". And then, every time that the object.Y is greater than yLimit, you add yLimit to itself and trigger the event that you want.

    I made a little example, it' in my Drive:

    drive.google.com/file/d/1DrZbXNXvIXdRJwF_-OqsgrUXO5u3IWfe/view

    Hope it helps,

    Isaac

  • Use behavior Bullet on you object then set an instance variable "example_A" to 1

    bullet distance traveled = 1000 * "example_A"

    event action + add to example_A + 1

    This uses distance traveled rather than coordinate to trigger.

  • sinfulj's example is close to a good solution.

    It has a few pitfalls though.

    You will want to make sure you are in a 1000 pixels range of your next "iteration".

    So have your instance variable "fallDist" which will be equal to 0, 1, and so on. Its default value should be 0 though.

    Then your condition should be :

    Bullet distance travelled >= [(greater or equal)] to 1000 * (fallDist+1)

    And as action, you do indeed add 1 to fallDist and any other of the actions you want to happen on a regular basis every 1000 pixels.

  • Thanks guys for the suggestion I'll try them out and let you know if I was able to acheive the result I'm looking for. Although I should have told you that I'm using the Physics behavior and not the bullet behavior.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I was assuming the bullet behavior was already enabled.

    If distFall=0 at the start when it hits 1000px it will stay 1000.

    Anyways I've only been coding for bouts 2 months. Sorry I i got it wrong

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