Trigger an event when object reaches a location

Get help using Construct 2

Post » Wed Nov 04, 2015 12:34 am

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.

Image
B
5
S
1
Posts: 85
Reputation: 545

Post » Wed Nov 04, 2015 12:48 am

Try this
pathx=int(sprite.x)
pathy=int(sprite.y)
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Wed Nov 04, 2015 1:21 am

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.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Wed Nov 04, 2015 1:48 am

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 :P

Image
B
5
S
1
Posts: 85
Reputation: 545

Post » Wed Nov 04, 2015 2:11 am

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?
B
5
S
1
Posts: 85
Reputation: 545

Post » Wed Nov 04, 2015 6:39 am

@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.
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Wed Nov 04, 2015 10:13 am

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

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

No idea. can only guess from your description.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Wed Nov 04, 2015 2:48 pm

Message: Santhenar can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
@jojoe

Point taken :D

Hope this works.

https://www.dropbox.com/s/i6qi9gwhq3ro1 ... .capx?dl=0

Arrghhh not enough rep!

https://www.dropbox.com/
s/i6qi9gwhq3ro111/
lines.capx?dl=0
B
5
S
1
Posts: 85
Reputation: 545

Post » Wed Nov 04, 2015 3:31 pm

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?
B
5
S
1
Posts: 85
Reputation: 545

Post » Wed Nov 04, 2015 3:44 pm

"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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests