# If object is moving...

Get help using Construct 2

### » Thu Feb 06, 2014 5:11 pm

I'd like for enemy helicopters to tilt in the direction they are moving, but straighten up when they are not. How do I tell C2 to check if an object is moving positively or negatively along the x-axis?
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

### » Thu Feb 06, 2014 6:06 pm

Movement behaviors do often have an "Is moving"-condition and also expressions that return the X and Y vectors.

Here is a very simple example that should be similar to what you had in mind:
B
27
S
6
G
11
Posts: 1,051
Reputation: 8,173

### » Thu Feb 06, 2014 7:45 pm

That works great. So "vector" defines the movement direction? This helps a lot. Thank you.
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

### » Thu Feb 06, 2014 8:35 pm

I'm still having some difficulty. The enemy helicopter doesn't have "is moving" because it's not controlled by the player and doesn't have an "8Direction" behavior assigned to it. It has a Bullet Behavior assigned to it. VectorX won't work either because it's associated with the "8direction" behavior.

Is there any other way to achieve this either using the bullet behavior or just checking if the enemy object is moving?
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

### » Thu Feb 06, 2014 8:48 pm

That really depends on how you are implementing the movement. A bit of code might clear things up.
B
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

### » Thu Feb 06, 2014 9:01 pm

Yes well, with the Bullet behavior you can work with the "Speed" and "AngleOfMotion"-expressions.

If the speed is over 0 the sprite is obviously moving and the angles of motion would be 0 for right and 180 for left.

You might be doing something more complicated, in which case a code snippet would indeed help like blackhornet mentioned.
B
27
S
6
G
11
Posts: 1,051
Reputation: 8,173

### » Thu Feb 06, 2014 9:05 pm

Sure, this is what I have. Bullet behavior is attached to the enemy with set angle off so the enemy is always facing the same direction.

Enemy - Bullet distance traveled > 150 | Enemy - Set Bullet Speed to 0

Then I wait a second and send it back the other way. I'd like for it to tilt when moving forward and backward.
Boony2014-02-06 21:16:20
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

### » Thu Feb 06, 2014 9:21 pm

B
27
S
6
G
11
Posts: 1,051
Reputation: 8,173

### » Thu Feb 06, 2014 9:24 pm

I tried Comparing Bullet Speed.

Enemy - Bullet Speed Greater than 0 | Enemy Rotate 1 degrees toward 8.

But when it moves backwards, it stays at that angle.
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

### » Thu Feb 06, 2014 9:28 pm

Awesome! I'm going to study how you did that. Thanks, PixelRebirth.
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Next