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

One response to “RPGMaker MZ – Get Distance from Event to Player”

  1. A WordPress Commenter Avatar

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

Leave a Reply

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