How do I find out if an object is in motion?

Get help using Construct 2

Post » Tue Jul 07, 2015 4:46 pm

I want to create a condition in which if this object is in motion, do a certain function. But the object doesn't have any behavior on it and I'm hoping not to put any. How do I go about making such a condition?

I was hoping if there is something to do with comparing the X value but that would need a global variable to it.

Any help?
B
26
S
1
Posts: 59
Reputation: 1,100

Post » Tue Jul 07, 2015 4:53 pm

Give the object two instance variables, oldX and oldY. Every tick, set oldX to Object.X and oldY to Object.Y. To check if Object is moving, in an event before you update oldX and oldY, check if oldX is different from X OR oldY is different from Y. If one of the two is different, Object has moved.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Tue Jul 07, 2015 4:58 pm

Thanks. I guess this is the best way to do it.
B
26
S
1
Posts: 59
Reputation: 1,100

Post » Tue Jul 07, 2015 9:02 pm

Another way would be to use a Boolean variable "moving" and set it to true every time you change the object's position.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 35 guests