Trigger an event when object reaches a location

0 favourites
  • 11 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Hi,

    I have a very simply trigger which I do not know why it is not firing.

    My object has 2 variables: PathX and PathY. The object moves towards these coordinates at the rate of 1 pixel (for testing)

    When it arrives it should trigger an event.

    The conditions are:

    PathX = Sprite.X

    PathY = Sprite.Y

    Yet the event does not trigger.

    If I replace these conditions with OnKeyPressed, it works fine, so it's not a problem with the event. I'm really baffled and it must be something simple I am doing wrong.

  • Try this

    pathx=int(sprite.x)

    pathy=int(sprite.y)

  • Try pulsing it with an "on every tick". Some times that helps me.

    Also, if your sprite is moving, it is going to be next to impossible to register, unless you are inputting the exact X,Y location.

    Try a distance to check if it is "near" enough to the sprites X and Y. Giving it 4-8 pixels of "slop" might make it register more often for you.

    These are just guesses. It would be better if you could post a Capx.

  • Thanks guys!

    Using int(sprite.x) makes it work about 80% of the time.

    But that reduces as soon as I increase the speed above 1px.

    I did already try and put in a function which would calculate the distance between the object and the finishing point and teleport it if it got close enough, but it's pretty ropey.

    It goes

    System - distance(Sprite.X,Sprite.Y,Sprite.PathX,Sprite.PathY) < 10

    set sprite.x to pathX

    set sprite.y to pathY

    But it it always triggers regardless of distance. Not sure what's going on there.

    I'm afraid a capx probably won't help, it's quite messy at the moment

  • This is really messed up...

    System - distance(Sprite.X,Sprite.Y,Sprite.PathX,Sprite.PathY) < 10

    set sprite.x to pathX

    set sprite.y to pathY

    When the less than value is set to 10, the object never teleports.

    However, when the less than value is set to 5, it does.

    How does that make any goddamn sense at all?

  • Santhenar

    Instead of setting actions when the event is triggered (which I'm guessing it goes true for a very brief moment and then returns to false), try to set a boolean to true.

    Then create a new event bellow, check if the boolean is true (which will be the case if the event was triggered even for a brief moment) and do your actions there. Maybe that will help.

  • "I'm afraid a capx probably won't help, it's quite messy at the moment "

    "How does that make any goddamn sense at all?"

    No idea. can only guess from your description.

  • jojoe

    Point taken <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    Hope this works.

    dropbox.com/s/i6qi9gwhq3ro1 ... .capx?dl=0

    Arrghhh not enough rep!

    dropbox.com

    s/i6qi9gwhq3ro111/

    lines.capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay I think I'm beginning to see what some of the problems are here.

    It works when there is only 1 sprite in existence, but when more are added it starts to break down.

    This is because when it is calculating distances or toggling variables it is doing it for all instances instead of one at a time.

    So IF sprite distance < 10, toggle boolean to true.

    When ANY sprite is close to a node it sets the boolean for ALL sprites.

    I suppose because the distance check is running as a system action, but it doesn't seem possible to run a distance check as an object action... Is it?

  • "but it doesn't seem possible to run a distance check as an object action... Is it"

    Offcourse this is possible, would be weird if it wasn't, right?

    You just have to pick the object in the event, as explained in "how events work"

    the "system compare" condition doesn't pick, but a simple "system pick by comparison" does..

    Another option would be to add the system compare condition to a for each object event..

  • I found a different way of doing it

    Thanks for your help!

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