像素游戏中非玩家角色(Non-Player Character,NPC)的运动通常缺乏自然度,其中最为突出的表现是NPC的运动路径固定且运动姿态生硬,严重影响游戏的趣味性、神秘感和生命力。为改善上述问题,提出了一种能保障运动路径简洁、平顺、难以预测且运动姿态自适应变化的NPC运动优化生成方法。首先,融合RRT-Connect算法、粒子群优化算法和Bresenham算法,提出一种新颖的双层次优化方法,快速、有效且高随机性地为NPC自动生成运动姿态关联且初步可行的运动路径。其次,基于贪心策略对初步可行运动路径进行精简,以缩短路径长度,并提升路径的平顺性。最后,基于粒子群优化算法,提出一种路径转角平顺方法,进一步优化运动路径和运动姿态,形成高自然度的NPC运动。针对不同复杂度的地图和不同形状及尺寸的NPC,对所提方法开展有效性验证,结果表明,该方法生成的NPC运动路径具有简洁、平顺、高随机性且运动姿态自适应变化的显著特点。同时,有别于现有的相关工作,该方法具有提升像素游戏中NPC运动自然度的巨大潜力。
The unnatural motion of non-player characters (NPCs) is a common issue in pixel art games. This is especially obvious when an NPC is in motion where it usually moves along a pre-fixed path with a stiff motion posture,which significantly detracts from the game's fun, mystery, and/or vitality. To handle the above issue, i.e., generating a concise, smooth, and unpredictable motion path where an NPC can move along it by using adaptable postures, this study proposes a new motion generation approach based on optimization. Firstly, a novel two-level optimization method is presented, which integrates the RRT-Connect algorithm, particle swarm optimization, and Bresenham algorithm. It can rapidly, effectively, and automatically generate a preliminarily feasible and high-random motion path while also optimizing motion postures. Secondly, a greedy strategy is applied to simplify the generated path, shortening the length and improving the smoothness. Finally, based on the particle swarm optimization, a smoothing corner method is developed to further optimize the above-mentioned path and its related postures as well, resulting in final high-naturalness motion. The effectiveness of the proposed approach is verified through tests on several maps of varying complexities and NPCs with different shapes and sizes. The results demonstrate that the generated motion paths exhibit high randomness and the motion postures show significant adaptability. Meanwhile, compared with the existing related works, the proposed approach demonstrates great potential in enhancing the naturalness of NPC motions in pixel games.
[1]HART P E, NILSSON N J, RAPHAEL B. A formal basis for the heuristic determination of minimum cost paths[J]. IEEE Transactions on Systems Science and Cybernetics, 1968,4(2):100-107.
[2]沈克宇,游志宇,刘永鑫,等.基于改进A*算法的移动机器人路径规划[J].计算机应用研究,2023,40(1):75-79.
[3]李子涵,孙建红,王永利.基于A*算法的电子游戏路径优化处理[J].电子设计工程,2021,29(13):1-5.
[4]陆皖麟,雷景森,邵炎.基于改进A*算法的移动机器人路径规划[J].兵器装备工程学报,2019,40(4):197-201.
[5]郭园园,袁杰,赵克刚.基于改进A算法和动态窗口法的机器人路径规划[J].计算机工程与科学,2022,44(7):1273-1281.
[6]宛博文,陈洁,朱瑞晨,等.改进的A*算法在游戏寻路功能中的应用与研究[J].信息化研究,2019,45(6):51-55.
[7]华洪,张志安,施振稳,等.动态环境下多重A*算法的机器人路径规划方法[J].计算机工程与应用,2021,57(10):173-180.
[8]LAVALLE S M. Rapidly-exploring random trees: A new tool for path planning[J]. The annual research report, 1999[2023-09-08]. https://api.semanticscholar.org/CorpusID:14744621.
[9]崔春雷,陈诗豪,沈超航,等.基于改进Bi-RRT的移动机器人路径规划算法[J].计算机测量与控制,2022,30(5):181-185.
[10]臧强,张国林,靳雨桐,等.一种基于动态步长的AAPF-RRT*移动机器人路径规划新算法[J].中国科技论文,2021,16(11):1227-1233.
[11]叶鸿达,黄山,涂海燕.基于改进Bi-RRT*算法的移动机器人路径规划[J].电光与控制,2022,29(2):76-81.
[12]龙建全,梁艳阳.多路口环境下RRT的最优路径规划[J].计算机工程与应用,2020,56(19):273-278.
[13]刘奥博,袁杰.目标偏置双向RRT*算法的机器人路径规划[J].计算机工程与应用,2022,58(6):234-240.
[14]王杨斌,章伟,王为科,等.改进Informed-RRT*的动态环境路径规划算法[J].电光与控制,2022,29(5):28-32.
[15]KUFFNER J J, LAVALLE S M. RRT-connect: An efficient approach to single-query path planning[C]//Proceedings 2000 ICRA. Millennium Conference. IEEE International Conference on Robotics and Automation. Symposia Proceedings. April 24-28, 2000, San Francisco, CA, USA. IEEE, 2000:995-1001.
[16]张瑞,周丽,刘震锴.基于MOBDB-RRT*算法的移动机器人路径规划[J].电光与控制,2022,29(7):12-16,36.
[17]BRESENHAM J E. Algorithm for computer control of a digital plotter[J]. IBM Systems Journal, 1965,4(1):25-30.
[18]BRESENHAM J E. Ambiguities in incremental line rastering[J]. IEEE Computer Graphics and Applications, 1987,7(5):31-43.
[19]朱浩,赵清海,郑群锋,等.改进粒子群算法的自动充电机械臂时间最优轨迹研究[J].机械科学与技术,2024,43(3):423-429.