Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Way to check if actor is adjacent to any other actor?

A topic by DoctorSpacebar created Jul 10, 2023 Views: 154 Replies: 2
Viewing posts 1 to 2

I'm working with the plugin right now. How would I go about checking if a given actor is adjacent to any other actor? I am willing to use scripts, and in fact that would be ideal as I plan to loop through this for each actor.

Developer(+1)

All map battlers are Game_Character objects. This means that you can pull their tile X and Y coordinates directly.

For finding out if an actor is next to another actor, the $gameMap.distance(cx1, cy1, cx2, cy2) value must be <= 1.

You must also check through all actors on the map.

Script (assuming the current battler is an actor);

----------

const map_battler = $gameMap.selectedBattler();

const actors = $gameMap._actors.filter((actor_map)=>{

  return actor_map != map_battler;

})

if(!map_battler._battler.isActor())return

const cx1 = map_battler.x;

const cy1 = map_battler.y;

return (

  actors.some((actor_map)=>{

    const cx2 = actor_map.x;

    const cy2 = actor_map.y;

    const distance = $gameMap.distance(cx1, cy1, cx2, cy2);

    return distance <= 1;

)


----------

Haven't tested this but this should tell you if any actor is near the current map selected actor

(1 edit) (+1)

Thanks! About to go to work, but I'll implement this when I'm back and see how it goes.


EDIT: It works! Thanks again for the help.