Checking for tile collision?

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
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 :)
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
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.
 

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
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?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,692
Reaction score
1,105
First Language
Portuguese - Br
Primarily Uses
RMMZ
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.
 

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
Just what I needed! Will direction accept the up/down input or the numeric value of the directions?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,692
Reaction score
1,105
First Language
Portuguese - Br
Primarily Uses
RMMZ
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())
 

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
This worked like a charm, thank you!
 

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
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?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,069
Reaction score
1,488
First Language
EN
Primarily Uses
RMMZ
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:
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;
};
 

Woland

Veteran
Veteran
Joined
Mar 26, 2017
Messages
350
Reaction score
98
First Language
Polish
Primarily Uses
RMMV
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.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,069
Reaction score
1,488
First Language
EN
Primarily Uses
RMMZ
Yep, it's defined for all characters. Just swap $gamePlayer for the appropriate character reference, e.g. $gameMap.event(5). :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Hope you are all fine today~
Moderators, you must have so much patience to be able to deal with everything. I mod in a server of sorts and today we just got a message, which, despite it's helpful constructive criticism, basically stated that all of the mods were jerks and that was the only reason our server was unlikeable. So, thank you, for having patience. You are appreciated! :kaoluv:
Haired slime? Trying some different styles of art. Maybe I can make some resources with this new kind of painting.......
i love my game very much

Forum statistics

Threads
105,737
Messages
1,015,982
Members
137,417
Latest member
Knife77
Top