Turn player towards event

I'm trying to get a player to turn towards an NPC. I looked at set move route but it doesn't have that option. I have a trapdoor spider event. The character jumps back when he touches its cobwebs and hears a screech. The web can be touched from any of the four directions. Then a giant spider pops out. I want them to face the spider. Any suggestions?
If the player faces the web when touching it, and then jumps back, wouldn't they already be facing the spider? Or does the spider pop out from somewhere other than the web?

I would do a Set Move Route on the spider to make it turn towards the player, and then do a Set Move Route on the player, with a script call to
Code:
set_direction(10 - $game_map.events[id])

where id is the event id of the spider, with no leading zeros.

This will make the spider face the player, and then make the player face 180 degrees to the spider's facing direction). So if the spider is facing up, the player will be facing down, and if the spider is facing right, the player will be facing left.

If you try it and it doesn't work, please give a screenshot of your event showing that script call, a screenshot of the spider event, and tell us what the error message is. When you do your screenshots, include the whole event window, not just the list of commands, because I'll need to see more than just the commands.
Didn't work. 🙁
sorry - that was only half complete.

Code:
set_direction(10 - $game_map.events[id].direction)

I would expect the first error "undefined local variable or method 'id'" to happen if you had entered the code exactly as I had it, without replacing id with the event number.
$game_player.turn_toward_character($game_map.events[eventID][1])

events are characters by definition.
VX doesn't have turn_toward_character - only turn_toward_player.
Code:
def turn_toward_character(character)
    sx = distance_x_from(character.x)
    sy = distance_y_from(character.y)
    if sx.abs > sy.abs
      set_direction(sx > 0 ? 4 : 6)
    elsif sy != 0
      set_direction(sy > 0 ? 8 : 2)
    end
  end

turn_toward_player implies turn_toward_character(player)
Yes, but that function is not in VX by default. It was only expanded in Ace. I provided a way to do this that doesn't require script mods.

Also, is this valid?
$game_map.events[eventID][1]

Doesn't $game_map.events[n] return an event, rather than an array?
$game_map.events is a hash.
I remembered somebody pointing out that events[id] would return a pair, so x[1] would return the actual event.

IDK, if events[id][1] doesn't work, just remove the [1]

(I always get that mixed up somehow)
ah yeah. When you do $game_map.events[id] you're getting the event. But when you do $game_map.events.for_each you're getting the key/value pair. That one has tripped me up a few times in the past as well.
I screwed up again. This was supposed to be in vx ace. Not vx. I blame my ADD. Which is prolly why this isn't working.
then in a move route, do a script call with this:

Code:
turn_toward_character($game_map.events[id])

replacing id with the spider's event id, with no leading zeros.

The code I originally gave you would work in VX as well as Ace, but did you put the .direction at the end as per my second post?
Still can't get it to work. I tried the snippet posted by gstv87 too.
$game_player.turn_toward_character(event)

if you're on an event, you need to turn *the player* towards the event.
if you just write "turn_toward_character", you're in the event's space.
"turn_toward_character(id)" implies "self.turn_toward_character(id)", "self" being the event you are writing from.

when using move routes within the GUI tool, always mind the object space you're writing from.
If you do it the above way, you could just do $game_player.turn_toward_character(self) if the event you're putting the move route on is the spider.

You could also do it as a second move route and select the player from the drop down list, rather than the event.
That worked Shaz. Thank you!
Moved to: VX Ace

Original thread: https://forums.rpgmakerweb.com/threads/turn-player-towards-event.92178/