[GM] Making a enemy face you...

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 87
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
« Last Edit: March 04, 2014, 01:43:40 AM by modern algebra »

****
Rep:
Level 88
wrath of winter
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.

Want a personal sig like this? Ask Firerain:
http://rmrk.net/index.php/topic,20203.0.html

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
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

**
Rep: +0/-0Level 87
It works! ^_^ Thanks.

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
No problemo. ;8