How to perform an action once when sprite reaches a position

Just started using Construct 2? Post your questions here

Post » Wed Jul 30, 2014 10:03 pm

Back again! :D

I have a Sprite with the Platform behaviour. I am then simulating controls to make the player move automatically on load to the right.

When the player reaches a certain position I want to increase the movement speed and send the player back in the other direction.

To increase the speed I have the following event:
PlayerSprite | X <= 500 | Add 10 to MovementSpeed and then Set Platform maximum speed to MovementSpeed

It also then switches the direction from right to left, and I have another condition for when the player reaches the left side of the layout to again add more speed and send it back to the right.

It works fine - but it is adding multiple amounts of 10 - so it is firing more than once when it changes direction. I am at a loss to why this is happening. Not sure if it is because the player seems to have inertia so spends more than one tick at an X position of 500 or greater.

I tried having the condition being X is equal to 500, but it never fired because looking at the debug profiler it is never 500 exactly, it will be like 500.9875223355346567.

How can I make it fire the once?
You do not have the required permissions to view the files attached to this post.
Posts: 6
Reputation: 175

Post » Thu Jul 31, 2014 12:55 am

Try the System:Once on true condition. However it will still not be exactly equal to 500.000000. You could have a range check 499.99 <= X <= 500.01 instead.
Posts: 1,646
Reputation: 6,596

Post » Thu Jul 31, 2014 5:22 pm

Thanks, this additional condition on my existing condition for the sprite worked without any alteration!
Posts: 6
Reputation: 175

Return to Beginner's Questions

Who is online

Users browsing this forum: OokLoc and 0 guests