RPG Maker Forums

I'm currently writing an AI for a friendly follower event in an ABS game which uses Chrono Engine on RPG Maker MV and making good progress but am currently stuck on figuring out the best method for finding the real distance between the follower event and an enemy event. The distance functions I've found seem to detect the direct distance to coordinates and don't take obstacles like walls or the player into consideration. Currently I have it set to locate the closest target from all enemies and use that as its target but I'm trying to narrow it down further to eliminate enemies which can't be reached or can be reached but are much further than another enemy whose distance is technically further than the enemy blocked behind a wall.

xyzwall.png
where x = follower location, y = closest enemy event but path is blocked, and z = the intended target.

overall the problem is the follower event will bounce around trying to get through a wall to reach its closest target until another enemy gets closer to the follower and becomes the new target.

I was thinking maybe base a new function off of findDirectionTo and make it output the distance it would need to travel to reach its target thus giving me a real distance from target? Or am i just looking in the wrong place here?

any discussion pointing me in the right direction or assistance in solving this problem would be amazing and greatly appreciated.

EDIT:

I've managed to solve the issue by editing findDirectionTo to look like the code below. BUT it seems to be really choppy and game breaking. LoL

Will continue modifying my method of calling this function to see if its viable or not.


JavaScript:
Game_Map.prototype.realDistanceTo = function(x, y, goalX, goalY) {
    var searchLimit = this.searchLimit();
    var mapWidth = $gameMap.width();
    var nodeList = [];
    var openList = [];
    var closedList = [];
    var start = {};
    var best = start;

    if (this.x === goalX && this.y === goalY) {
        return 0;
    }

    start.parent = null;
    start.x = x;
    start.y = y;
    start.g = 0;
    start.f = $gameMap.distance(start.x, start.y, goalX, goalY);
    nodeList.push(start);
    openList.push(start.y * mapWidth + start.x);

    while (nodeList.length > 0) {
        var bestIndex = 0;
        for (var i = 0; i < nodeList.length; i++) {
            if (nodeList[i].f < nodeList[bestIndex].f) {
                bestIndex = i;
            }
        }

        var current = nodeList[bestIndex];
        var x1 = current.x;
        var y1 = current.y;
        var pos1 = y1 * mapWidth + x1;
        var g1 = current.g;

        nodeList.splice(bestIndex, 1);
        openList.splice(openList.indexOf(pos1), 1);
        closedList.push(pos1);
        
        if (current.x === goalX && current.y === goalY) {
            best = current;
            break;
        }

        if (g1 >= searchLimit) {
            continue;
        }

        for (var j = 0; j < 4; j++) {
            var direction = 2 + j * 2;
            var x2 = $gameMap.roundXWithDirection(x1, direction);
            var y2 = $gameMap.roundYWithDirection(y1, direction);
            var pos2 = y2 * mapWidth + x2;

            if (closedList.contains(pos2)) {
                continue;
            }
            if (!$gamePlayer.canPass(x1, y1, direction)) {
                continue;
            }

            var g2 = g1 + 1;
            var index2 = openList.indexOf(pos2);

            if (index2 < 0 || g2 < nodeList[index2].g) {
                var neighbor;
                if (index2 >= 0) {
                    neighbor = nodeList[index2];
                } else {
                    neighbor = {};
                    nodeList.push(neighbor);
                    openList.push(pos2);
                }
                neighbor.parent = current;
                neighbor.x = x2;
                neighbor.y = y2;
                neighbor.g = g2;
                neighbor.f = g2 + $gameMap.distance(x2, y2, goalX, goalY);
                
                if (!best || neighbor.f - neighbor.g < best.f - best.g) {
                    best = neighbor;
                }
            }
        }
        
    }

    var node = best;
    
    var nodeCount = 2;
    while (node.parent && node.parent !== start) {
        node = node.parent;
        nodeCount++;
    }
    
    return nodeCount;
    
};

Game_Map.prototype.searchLimit = function() {
    return 12;
};

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top