Checking for tile collision?

Hey, so this:

$gameMap.terrainTag($gameVariables._data[71],$gameVariables._data[72]) == 7

Checks the terrain tag of tile XY (where x = variable 71 and y = variable 71)

How do I check the tile's collision? I want to check if the specific tile has a collision or not 🙂
You could Paint a Region ID as collision indicator. Than you check if the target destination got Region ID1 or not.

Terrain Tag could also work, but i liked Regions better, or combine both of them.

The 3rd one could be a Range of Event Ids on that Position, for example Events 1 to 30 are collision Events.

Depending on what you need it needs different approaches.
Can't I just ask in JS if that particular tile has a collision or not? I mean, the info has to be stored somewhere?
Hi!
If when you mean collision, you mean if the player can walk above the tile, you can check with the script call:
$gameMap.isPassable(x, y, direction)
It will return true if the player can walk through these tiles in the specified direction.
Just what I needed! Will direction accept the up/down input or the numeric value of the directions?
Just what I needed! Will direction accept the up/down input or the numeric value of the directions?
The numeric value: 2,4,6,8...
If you are making the check for the player, you can do this:
$gameMap.isPassable(x, y, $gamePlayer.direction())
This worked like a charm, thank you!
Necro, but I need to upgrade this.

$gameMap.isPassable(x, y, $gamePlayer.direction()) seems to only work for the map collisions.

What about if I want to check for all collisions? Not just the map, but also collisions with all other events that are on the "Same as player" priority?
JavaScript:
$gamePlayer.canPass(x, y, d);
This checks various things:
  • If the target is outside map bounds, movement is blocked;
  • If the character is marked "Through", movement is allowed;
  • If the map is not passable both to and from the target, movement is blocked;
  • If there is a collidable character on the target tile, movement is blocked.
Example usage:
JavaScript:
$gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, $gamePlayer.direction());
Definition from core scripts (rpg_objects.js v1.6.2), for reference:
Spoiler: Game_CharacterBase > canPass
JavaScript:
Game_CharacterBase.prototype.canPass = function(x, y, d) {
    var x2 = $gameMap.roundXWithDirection(x, d);
    var y2 = $gameMap.roundYWithDirection(y, d);
    if (!$gameMap.isValid(x2, y2)) {
        return false;
    }
    if (this.isThrough() || this.isDebugThrough()) {
        return true;
    }
    if (!this.isMapPassable(x, y, d)) {
        return false;
    }
    if (this.isCollidedWithCharacters(x2, y2)) {
        return false;
    }
    return true;
};
thanks @caethyril - will it work for other events, too? Not just for the player character? I want to push a boulder down an ice patch and stop when it collides when another boulder.
Yep, it's defined for all characters. Just swap $gamePlayer for the appropriate character reference, e.g. $gameMap.event(5). 🙂
Works, thank you!

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-tile-collision.123701/