[Solved] How can a player turn towards an event on "Event Touch"?

I have NPCs that go on their business but do a "greeting" whenever they touch the hero. I do not know how to make the hero turn towards the NPC that is greeting her.

I attached a screenshot to illustrate this: red dress is the hero, an NPC north (above) of her proceeds on his path south (down).

EventQuestion.png


NPC touches the hero while the hero is looking south (down). At that point a greeting event fires off. The inconvenience is that the hero is looking down, yet it would be so much better if she turned towards the NPC just before her part of the greeting.

Would anyone have suggestions on how to maker her turn towards an event that touches her?

Thank you.
If the event is always going from up, why not just set player face up? Unless event is using pathfinding, but I don't think so if you didn't mentioned this.
@fizzly, thank you.

Indeed, the movement is every which way, imitating pedestrian traffic.

Some NPCs move in straight line, other NPCs have L-like looking paths:

EventQuestion2.png

I've moved this thread to MZ Support. Thank you.

In that case, make a condition branches. If pedestrian is looking right, then turn player left. If pedestrian looking down, then turn player up. And do 4 conditions for every direction, before they start to talk.
And if you use it a lot then you could make it a common event (in the database), e.g.
Spoiler: Event example
◆If:This Event is facing Down ◆Set Movement Route:Player (Wait) : :◇Turn Up ◆ :Else ◆If:This Event is facing Left ◆Set Movement Route:Player (Wait) : :◇Turn Right ◆ :Else ◆If:This Event is facing Right ◆Set Movement Route:Player (Wait) : :◇Turn Left ◆ :Else ◆Set Movement Route:Player (Wait) : :◇Turn Down ◆ :End ◆ :End ◆ :End
Then just call that at the start of every NPC event that does this~
I hesitate to enter into an MZ discussion, but in Ace this could be done with a simple script call in the set move route of the NPC. Obviously this would need to be translated from Ruby to Javascript, (e.g. I believe $game_map becomes $gameMap, but beyond that I don't know) but once that is done, might it work?

In the greeting event command on the NPC, include a set move route with the subject 'Player', then use this within that move route:

Script: turn_toward_character($game_map.events[15])

Change the [15] to the id of the NPC.
@caethyrill, thank you! I tested it and it works like a charm, here is an illustration:



caethyril's code inside a common event:

PFE01.png


Then every NPC calls it from their "greeting" event page:

PFE02.png
@Sepheyer: great, happy RPG Making~ 😂

In the greeting event command on the NPC, include a set move route with the subject 'Player', then use this within that move route:

Script: turn_toward_character($game_map.events[15])
I think the RMMV/Z equivalent would be this, in a move route Script:
JavaScript:
this.turnTowardCharacter($gameMap.event(15));
Personally, I think I'd suggest this instead, in a standalone Script command:
JavaScript:
$gamePlayer.turnTowardCharacter(this.character(0));
I.e. "make the player turn towards This Event". I was avoiding script calls to show it can be done with no scripting knowledge, but this is a nice concise alternative!
@caethyril, @Kes - thank you! I absolutely prefer the JS option.

Integrated, tested, works great.
@caethyril, where would I find reference to "turnTowardCharacter"?

The console doesn't show it unless you typed "turn". So, can't learn about this function from console.

This isn't in the "rmmz_objects.js". So, not there either.

Not in the very helpful reference posted by @Archeia.

Could you let me know how I can go about learning about functions such as TTC, which appears to me to be undocumented so far.

Thank you.
@caethyril, where would I find reference to "turnTowardCharacter"?

The console doesn't show it unless you typed "turn". So, can't learn about this function from console.

This isn't in the "rmmz_objects.js". So, not there either.
Actually, it is defined in rmmz_objects.js: line 7803 (v1.3.2). 👋

I learned about the various methods by spending a lot of time reading through the core scripts. Lots of Ctrl+F! If you want to learn in a similar way, consider starting with the event commands in rmmz_objects.js: each of them are labelled with a comment, e.g. // Show Picture.

There are various resources for learning about RMMV's core scripts, e.g.


RMMZ's core scripts use similar method names and flow control in many areas so those might help. Not sure if there's anything similar for RMMZ. You might find something helpful on one of these boards:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-how-can-a-player-turn-towards-an-event-on-event-touch.139588/