I'm not sure if this is the right forum to ask but suppose I have an event that sets the movement route for the player that's triggered when they interact with an NPC. If the NPC is accessible from multiple sides how do I make it so the player always goes where I want them to, and not a tile or two off if they have triggered from the wrong side?
Player Movement Question
RPG Maker MZ SupportA Conditional Branch let's you check an events viewing direction.
You can use that to define 4 individual move routes.
You can use that to define 4 individual move routes.
Yeah, the other way around is using script or a mix of event and commands.
It is also optional to turn player through on during the scene, just in case another NPC is in the way so he has to move around in a longer route.
Edit*
Another trick is to make the player through on, take a step so he moves into the NPC, they he can moves from there.
Unless the NPC is a door or stone it may look wrong if your player moves inside it.
◆Gather Followers◆Change Player Followers:OFF◆Set Movement Route:Player (Wait): :◇Through ON◆Script:var thisEvent = $gameMap.event(this._eventId);: :$gamePlayer.goalX = thisEvent.x + 3;: :$gamePlayer.goalY = thisEvent.y;: :$gamePlayer.goalEvent = thisEvent;◆Loop ◆If:Script:$gamePlayer.x==$gamePlayer.goalX&&$gamePlayer.y==$gamePlayer.goalY ◆Break Loop ◆ :End ◆Script:$gamePlayer.setDirection($gamePlayer.findDirectionTo($gamePlayer.goalX,$gamePlayer.goalY)); ◆Set Movement Route:Player (Wait) : :◇1 Step Forward ◆Set Movement Route:This Event : :◇Turn toward Player ◆:Repeat Above◆Script:$gamePlayer.turnTowardCharacter($gamePlayer.goalEvent);◆Set Movement Route:Player (Wait): :◇Through OFFIt is also optional to turn player through on during the scene, just in case another NPC is in the way so he has to move around in a longer route.
Edit*
Another trick is to make the player through on, take a step so he moves into the NPC, they he can moves from there.
Unless the NPC is a door or stone it may look wrong if your player moves inside it.
If you turn trough on, you can just do "1 step forward". You are now on the same tile as the NPC, no matter what way you approached him from.
lol
Oh, I just edited the post.
You can also use the basic pathfinding function inside a move route (using Script call) for the player (set the move route to repeat and it will stop the when completed, otherwise the player will only move once - you can check wait for completion if needed).
This example is from the MV/MZ Script Call Spreadsheet:
If you need the player to stand in front of the event (this example will be for event 1) no matter what, you can change var x and y to:
This example is from the MV/MZ Script Call Spreadsheet:
JavaScript:
// Path to (2, 6) using the built-in pathfinding
var x = 2, y = 6, d = this.findDirectionTo(x, y); if (!d || !this.canPass(this.x, this.y, d)) { this.forceMoveRoute({ list: [{ code: 0 }] }); this.setMovementSuccess(true); this._moveRouteIndex--; } else this.moveStraight(d);
If you need the player to stand in front of the event (this example will be for event 1) no matter what, you can change var x and y to:
JavaScript:
var m = $gameMap, x = m.event(1).x, y = m.event(1).y + 1, d = this.findDirectionTo(x, y); if (!d || !this.canPass(this.x, this.y, d)) { this.forceMoveRoute({ list: [{ code: 0 }] }); this.setMovementSuccess(true); this._moveRouteIndex--; } else this.moveStraight(d);
haha, 2 souls, 1 mind.
Thanks, this worked perfectly for me.
Original thread: https://forums.rpgmakerweb.com/threads/player-movement-question.176088/