Setup
Conditions: None
Graphic: Evil 6 (Can be changed)
Autonomous Movement: Type: Fixed (Can be changed)
Speed: 3
Freq: 3
Options: Walking Animation
Priority: Same as Characters
Trigger: Parallel Process
Facing Down
Quote:@>Conditional Branch: This event is Facing Down
: Branch End
You'll want to start with just one direction. It's much easier to copy and paste this conditional branch once it's finished than make each one separately. You should uncheck 'Set handling when condtions do not apply'.
Quote: @>Control Variables: [0001: Player X] = Player's Map X
@>Control Variables: [0002: Player Y] = Player's Map Y
@>Control Variables: [0003: Enemy X] = This event's Map X
@>Control Variables: [0004: Enemy Y] = This event's Map Y
This sets the variables that will be needed. It records the player's map position and the enemy's map position so that they can be compared later.
Quote: @>Control Variables: [0002: Player Y] -= Variable: [0004: Enemy Y]
This is where it starts getting confusing. I'm going to use a small graph since that's how I figured it out.
http://img.photobucket.com/albums/v437/Metora/Tutorials/FacingDown.png[/img]
In this example, you can see that the X variables must be equal (which is included later), but you need to find the difference of the Y variables. In this example, the enemy's coordinates are (2,2) and the player's coordinates are (2, 3). To make the variable positive, I'm subtracting the enemy Y from the player Y:
3-2=1
Quote: @>Conditional Branch: Variable [0001: Player X] == Variable [0003: Enemy X]
: Branch End
The X coordinates must be equal.
Quote: @>Conditional Branch: Variable [0002: Player Y] [color=blue]Conditional Branch: Variable [0002: Player Y] >= 0
: Branch End
This is needed because variables can be both positive and negative. If you don't have this, the enemy will be able to see behind him infinitely.
Quote: @>Control Switches: [0001: Death] = ON
This is a switch and not a self switch because you'll probably want the enemy to give up the chase after a certain amount of time. If you want them to chase the player until they catch them, you can use a self switch instead.
Facing Left
After you copy and paste the event, you have to change a couple of things. Obviously, change the outermost conditional branch.
Quote: @>Conditional Branch: This event is Facing Left
If you forget to change this, your enemy will be able to see in all directions when facing down and be blind when facing left, right, or up.
Quote: @>Control Variables: [0003: Enemy X] -= Variable [0001: Player X]
http://img.photobucket.com/albums/v437/Metora/Tutorials/FacingLeft.png[/img]
Now, the enemy's coordinates are (2,2) and the player's coordinates are (1,2), so I subtracted the player's X from the enemy's X to make the variable positive.
2-1=1
Quote: @>Conditional Branch: Variable [0002: Player Y] == Variable [0004: Enemy Y]
: Branch End
This time, the Y coordinates must be equal.
Quote: @>Conditional Branch: Variable [0003: Enemy X] [color=blue]Conditional Branch: Variable [0003: Enemy X] >= 0
: Branch End
: Branch End
Now the X variable is used to determine the range.
Facing Right
This time, copy Facing Left so there's only a few things you have to change.
Quote: @>Conditional Branch: This event is Facing Right
First, don't forget to change this.
Quote: @>Control Variables: [0001: Player X] -= Variable [0003: Enemy X]
Just switch the player X and enemy X.
Quote: @>Conditional Branch: Variable [0001: Player X] [color=blue]Conditional Branch: Variable [0001: Player X] >= 0
: Branch End
: Branch End
Switch these lines from enemy X to player X.
http://img.photobucket.com/albums/v437/Metora/Tutorials/FacingRight.png[/img]
The enemy's coordinates are (2,2) and the player's coordinates are (3,2).
3-2=1
Facing Up
Copy the Facing Up conditional branch.
Quote: @>Conditional Branch: This event is Facing Up
Make sure you change this.
Change the subtraction line:
Quote: @>Control Variables: [0004: Enemy Y] -= Variable: [0002: Player Y]
You're just switching the player Y and enemy Y.
Quote: @>Conditional Branch: Variable [0004: Enemy Y] [color=blue]Conditional Branch: Variable [0004: Enemy Y] >= 0
: Branch End
: Branch End
Then switch the lines from player Y to enemy Y.
http://img.photobucket.com/albums/v437/Metora/Tutorials/FacingUp.png[/img]
The enemy's coordinates are (2,2) and the player's coordinates are (2,1).
2-1=1