设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 4112|回复: 7
打印 上一主题 下一主题

[交流讨论] 追逐战用的自动寻路

[复制链接]

Lv4.逐梦者

梦石
12
星屑
6246
在线时间
1196 小时
注册时间
2020-4-19
帖子
233

极短22获奖极短21参与

跳转到指定楼层
1
发表于 2020-4-20 23:26:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

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);
                                }
                        }
                }
        }
      
       
               
      }
    }
  };
})();

Lv4.逐梦者

梦石
0
星屑
7051
在线时间
1360 小时
注册时间
2018-12-16
帖子
1943
2
发表于 2020-4-20 23:49:30 | 只看该作者
Smart Pathfinding 自動馴鹿是我用過算最好的.

但是跟很多插件衝突.目前只好棄用了..
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
12
星屑
6246
在线时间
1196 小时
注册时间
2020-4-19
帖子
233

极短22获奖极短21参与

3
 楼主| 发表于 2020-4-21 00:02:50 | 只看该作者
play337 发表于 2020-4-20 23:49
Smart Pathfinding 自動馴鹿是我用過算最好的.

但是跟很多插件衝突.目前只好棄用了.. ...

居然还会有插件冲突吗。。看来后面我得多准备一些了。大佬有没有其他的寻路插件推荐呢?

点评

YEP_MoveRouteCore.js 你試試.不過對角移動好像不行.不過至少不會衝突.  发表于 2020-4-21 06:47
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
15512
在线时间
3951 小时
注册时间
2015-9-14
帖子
1333

开拓者

4
发表于 2020-4-21 00:26:13 | 只看该作者
Shaz 尋路插件簡單好用.
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
11199
在线时间
607 小时
注册时间
2016-8-25
帖子
1393

R考场第七期纪念奖

5
发表于 2020-4-21 09:34:08 | 只看该作者
太强了,
这个能在横版用吗(x
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
2
星屑
6639
在线时间
501 小时
注册时间
2018-3-23
帖子
533

R考场第七期银奖

6
发表于 2020-4-21 09:35:10 | 只看该作者
parent一看就是A*或者Dijkstra这种……
然而MV自带A*寻路。只要完全去除LIMIT限制就永远不会卡住了……(就是FPS可能会掉的很厉害
MV我不懂,但是我在VA写了一个TyPath自寻路欢迎捧场(逃
祝好。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

7
发表于 2020-4-21 12:21:21 | 只看该作者
自带的寻路我觉得很好。
但是太耗资源,到时候是电脑卡住,而不是人物卡住了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 12:24

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表