RPGMaker MZ – Get Distance from Event to Player

Get the distance from an Event to the player. If the event is smaller than 2 tiles, set self-switch A to ON.

var dist = $gameMap.distance($gamePlayer.x, $gamePlayer.y,
 $gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y);

if (dist <= 2) {

	$gameSelfSwitches.setValue([$gameMap._mapId, this._eventId, 'A'], true);

}

$gamePlayer.x and $gamePlayer.y get the location of the player.
$gameMap.event(this._eventId).x and y get the location of the event.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *