The RPG Maker Resource Kit

Other Game Creation => Other Game Making Programs => Topic started by: Identity on September 07, 2007, 01:56:44 AM

Title: [GM] Making a enemy face you...
Post by: Identity on September 07, 2007, 01:56:44 AM
I want to make it so that no matter where the enemy moves in the room, it'll always be facing in your general direction. How can I do this? :/

BTW I'm really tired as I write this so hopefully it makes sense. :D
Title: Re: Making a enemy face you...
Post by: iceflame1019 on September 07, 2007, 02:40:18 AM
hmmmm...well, I know that it involves multiple sprites if it's not top-down, but if it's TD then all you need is the right sprite-rotation codes.  Unfortunately my advice ends there...as of yet I am not very fluent in this area of GML.

I know that there are some rotation tutorials on the GMC that involve rotating to face the mouse, you could adapt those from mouse to player object.
Title: Re: Making a enemy face you...
Post by: Arrow on September 07, 2007, 02:53:53 AM
Very easily.

I'm assuming a number of things here, so replace the names of the objects and sprites as needed:

The player is called player_obj
The enemy is called enemy_obj
The enemy has a sprite for left and right facing- they are called face_left and face_right

Now you would do something like this in the enemy's step event. If you have more than two sprites, it gets a bit more complex, but it's easy enough to change.

Code: [Select]
if self.x<player_obj.x{self.sprite_index=face_right}
if self.x>player_obj.x{self.sprite_index=face_left}

That help?

Lemme know if I messed up, that was off the top of my head. :P
Title: Re: Making a enemy face you...
Post by: Identity on September 07, 2007, 03:32:00 AM
It works! ^_^ Thanks.
Title: Re: Making a enemy face you...
Post by: Arrow on September 07, 2007, 12:29:25 PM
No problemo. ;8