赞 | 84 |
VIP | 0 |
好人卡 | 0 |
积分 | 191 |
经验 | 0 |
最后登录 | 2025-1-10 |
在线时间 | 1309 小时 |
Lv4.逐梦者
- 梦石
- 12
- 星屑
- 7115
- 在线时间
- 1309 小时
- 注册时间
- 2020-4-19
- 帖子
- 250
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
我最近在做恐解的时候考虑到追逐战的事情,起初是用RM自带的接近,但事件在移动途中会出现乱窜的情况。
之后我又参考了一些设计追逐战的思路,做了XY若不对齐,就朝对应方向移动的事件。这个思路可以实现斜走,能在主角转弯的时候缩短距离,问题是遇到障碍物会卡住不动。
再然后我又查了查,然后看到了这个帖子
https://rpg.blue/thread-478963-1-1.html
我对里面wabcmcc大佬发的脚本改动了一下,让原来的脚本多了斜走寻路的功能。
这个脚本是以官方的寻路为基础的,可以用记事本打开rpg_objects.js来对关键名搜索,找到对应的官方寻路代码。
然后我在这个脚本的基础上添加了对斜方向的判断,因为官方寻路中有一个canPass函数来检测是否能走,所以我就借用了这个函数做判断,在斜走行不通的情况下换成直走来绕过障碍。
(凭什么moveStraight能绕过障碍,但moveDiagonally却不行)
目前测试了一下感觉还行,使用方法和说明一样。
总之我先分享一下。
//=============================================================================
// Smart Pathfinding
// by Shaz
// Last Updated: 2015.10.21
//=============================================================================
/*:
* @plugindesc Allows events or players to do smart Pathfinding
* @author Shaz
*
* @help
*
* Plugin Command:
* SmartPath eventId1 eventId2 # Makes event 1 find path to event 2
* SmartPath eventId x y # Makes event find a path to location x, y
* SmartPath eventId cancel # Cancel Pathfinding for event
*
* event = number for specific event
* event = 0 for "this" event
* event = -1 for player
* event = $gameVariables.value(x) to get the event id from variable x
*
* x, y = coordinates or $gameVariables.value(#) to use a variable coordinate
*
*/
(function() {
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toUpperCase() === 'SMARTPATH') {
subject = this.character(eval(args[0]));
if (args[1].toUpperCase() === 'CANCEL') {
subject.clearTarget();
} else if (args.length > 2) {
subject.setTarget(null, eval(args[1]), eval(args[2]));
} else {
subject.setTarget(this.character(eval(args[1])));
}
}
};
var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
_Game_CharacterBase_initMembers.call(this);
this._target = null;
this._targetX = null;
this._targetY = null;
};
Game_CharacterBase.prototype.setTarget = function(target, targetX, targetY) {
this._target = target;
if (this._target) {
this._targetX = this._target.x;
this._targetY = this._target.y;
} else {
this._targetX = targetX;
this._targetY = targetY;
}
};
Game_CharacterBase.prototype.clearTarget = function() {
this._target = null;
this._targetX = null;
this._targetY = null;
};
var _Game_CharacterBase_updateStop = Game_CharacterBase.prototype.updateStop;
Game_CharacterBase.prototype.updateStop = function() {
_Game_CharacterBase_updateStop.call(this);
if (this._target) {
this._targetX = this._target.x;
this._targetY = this._target.y;
}
if (this._targetX != null) {
if (this._x == this._targetX || this._y == this._targetY)
{
direction = this.findDirectionTo(this._targetX, this._targetY);
if (direction > 0)
{
this.moveStraight(direction);
}
}
else
{
direction = this.findDirectionTo(this._targetX, this._targetY);
if (this._x > this._targetX)
{
if (this._y > this._targetY)
{
if (this.canPassDiagonally(this._x, this._y, 4, 8))
{
this.moveDiagonally(4, 8);
}
else
{
if (direction > 0)
{
this.moveStraight(direction);
}
}
}
else if (this._y < this._targetY)
{
if (this.canPassDiagonally(this._x, this._y, 4, 2))
{
this.moveDiagonally(4, 2);
}
else
{
if (direction > 0)
{
this.moveStraight(direction);
}
}
}
}
else
{
if (this._y > this._targetY)
{
if (this.canPassDiagonally(this._x, this._y, 6, 8))
{
this.moveDiagonally(6, 8);
}
else
{
if (direction > 0)
{
this.moveStraight(direction);
}
}
}
else if (this._y < this._targetY)
{
if (this.canPassDiagonally(this._x, this._y, 6, 2))
{
this.moveDiagonally(6, 2);
}
else
{
if (direction > 0)
{
this.moveStraight(direction);
}
}
}
}
}
}
};
})(); |
|