Enemy chase system: Distance check works, but touch trigger fails

1766767966084.png
1766767995465.png

Hi everyone,

I'm struggling with a custom chase/escape system in RPG Maker MZ. I'm using two pages, both set to Parallel Process. While the detection and escape logic work perfectly, I cannot get the "touch/collision" to trigger using script calls.

The Setup:

  • Page 1 (Patrol/Detection): Trigger: Parallel.This code works fine to detect the player within a 3-tile vision cone and turns on Self Switch A:
    JavaScript

    var d = 3;
    var e = this.character(0);
    var p = $gamePlayer;
    Math.abs(e.x - p.x) + Math.abs(e.y - p.y) <= d && ((e.direction() == 2 && p.y > e.y) || (e.direction() == 8 && p.y < e.y) || (e.direction() == 4 && p.x < e.x) || (e.direction() == 6 && p.x > e.x))

  • Page 2 (Chase/Escape): Trigger: Parallel. Condition: Self Switch A is ON.The escape logic (distance >= 10) works perfectly to turn off Self Switch A:
    JavaScript

    $gameMap.distance(this.character(0).x, this.character(0).y, $gamePlayer.x, $gamePlayer.y) >= 10
The Problem:On Page 2, I have a second Conditional Branch (Script) to trigger a message/battle when the enemy touches the player. However, it never triggers, even when the event is right on top of the player.

I have tried:

  1. $gameMap.distance(this.character(0).x, this.character(0).y, $gamePlayer.x, $gamePlayer.y) <= 0.5
  2. this.character(0).pos($gamePlayer.x, $gamePlayer.y)
  3. this.character(0).x === $gamePlayer.x && this.character(0).y === $gamePlayer.y
All three of your conditions are checking "is the player on the same space as the event", but if the event has collision, then that'll never be true. The condition you want is "has the player collided with the event".

I think the following might do it, but I'm not quite sure:
JavaScript:
$gamePlayer.isCollided(this.character(0).x, this.character(0).y)

There are a few other collision functions but I'm not 100% sure how they're intended to work, so the above may be wrong; but the collision functions are probably what you need one way or another.
View attachment 356064View attachment 356065
Hi everyone,

I'm struggling with a custom chase/escape system in RPG Maker MZ. I'm using two pages, both set to Parallel Process. While the detection and escape logic work perfectly, I cannot get the "touch/collision" to trigger using script calls.

The Setup:

  • Page 1 (Patrol/Detection): Trigger: Parallel.This code works fine to detect the player within a 3-tile vision cone and turns on Self Switch A:
    JavaScript

    var d = 3;
    var e = this.character(0);
    var p = $gamePlayer;
    Math.abs(e.x - p.x) + Math.abs(e.y - p.y) <= d && ((e.direction() == 2 && p.y > e.y) || (e.direction() == 8 && p.y < e.y) || (e.direction() == 4 && p.x < e.x) || (e.direction() == 6 && p.x > e.x))

  • Page 2 (Chase/Escape): Trigger: Parallel. Condition: Self Switch A is ON.The escape logic (distance >= 10) works perfectly to turn off Self Switch A:
    JavaScript

    $gameMap.distance(this.character(0).x, this.character(0).y, $gamePlayer.x, $gamePlayer.y) >= 10
The Problem:On Page 2, I have a second Conditional Branch (Script) to trigger a message/battle when the enemy touches the player. However, it never triggers, even when the event is right on top of the player.

I have tried:

  1. $gameMap.distance(this.character(0).x, this.character(0).y, $gamePlayer.x, $gamePlayer.y) <= 0.5
  2. this.character(0).pos($gamePlayer.x, $gamePlayer.y)
  3. this.character(0).x === $gamePlayer.x && this.character(0).y === $gamePlayer.y
333.png

You could try something like this? This is what I have setup after the enemy catches me.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-chase-system-distance-check-works-but-touch-trigger-fails.181620/