# Object outside layout bug [SOLVED]

### » Fri Oct 14, 2011 3:52 pm

Hi everyone! In my game I use platform behavior for AI. Here is a part of enemy movement event sheet.

Everything works fine only when enemy goes outside from the right side of a screen. But when he leaves layout from the left he doesn't turn back. Any ideas why?Wolod2011-10-14 17:45:16
B
64
S
14
G
5
Posts: 265
Reputation: 6,129

### » Fri Oct 14, 2011 4:31 pm

Because the last event overrides the preceding event.

When the enemy leaves the layout to left, what do you suppose happens?

1. The event 3 is true, as it is outside layout and the angle is 180. Set the angle to 0.
2. Next, check the last event, keeping in mind that we now have angle at 0. Still outside layout? Yup. Angle equal to 0? Yup. Set angle to 180.

So what do we have here? An enemy that keeps turning back and forth just outside the layout.

You accidentally logic. ;)

Tip: you can condense those events this way-

+ enemy has wall to left
+ OR
+ enemy has wall to right
+ OR
+ enemy is outside layout
> enemy: set angle to enemy.Angle + 180 (180 becomes 0 and 0 becomes 180 )
> enemy: set horizontal speed to enemy.HorizontalSpeed * -1 (260 becomes -260, -260 becomes 260)

Just set the speed at start of layout or something and there you have it, everything you want in one event. :)Mipey2011-10-14 16:33:34
B
62
S
21
G
13
Posts: 1,910
Reputation: 13,685

### » Fri Oct 14, 2011 5:21 pm

[QUOTE=Mipey] Because the last event overrides the preceding event.

When the enemy leaves the layout to left, what do you suppose happens?

1. The event 3 is true, as it is outside layout and the angle is 180. Set the angle to 0.
2. Next, check the last event, keeping in mind that we now have angle at 0. Still outside layout? Yup. Angle equal to 0? Yup. Set angle to 180.

So what do we have here? An enemy that keeps turning back and forth just outside the layout.

You accidentally logic. ;)

Tip: you can condense those events this way-

+ enemy has wall to left
+ OR
+ enemy has wall to right
+ OR
+ enemy is outside layout
> enemy: set angle to enemy.Angle + 180 (180 becomes 0 and 0 becomes 180 )
> enemy: set horizontal speed to enemy.HorizontalSpeed * -1 (260 becomes -260, -260 becomes 260)

Just set the speed at start of layout or something and there you have it, everything you want in one event. :)[/QUOTE]
Thanks that worked!
B
64
S
14
G
5
Posts: 265
Reputation: 6,129

### » Fri Oct 14, 2011 6:52 pm

Except you shouldn't use or - it's buggy and can cause crashes.
Moderator
B
96
S
34
G
33
Posts: 3,007
Reputation: 27,911