本帖最后由 杰喵喵 于 2023-11-6 21:37 编辑
简单的agent飞行实现,步兵骑兵皆可,代码简单没有修改原本战团AI,十分傻瓜
一、理论指导:
1.【未写完】打败引擎硬核-关于骑砍各系统飞行等复杂位移功能实现与互相辅助 - MOD制作技术区 - 骑马与砍杀中文站论坛 - Powered by Discuz! (mountblade.com.cn)
2.自行百度或知乎"世界坐标系"与"自身坐标系的"相关知识。
3.改代码存在很多不足,请看下面大佬说明。
二、涉及核心函数:
1.(agent_set_no_dynamics, ":agent_no", 1),#设置是否飞行,0不飞行,1飞行
2.(position_has_line_of_sight_to_position, pos51, pos52)#两个点之间是否拥有直线视线,是否存在遮挡物
3.(agent_get_look_position, pos52, ":agent_no")#获取agent当前视角坐标pos
4. (agent_get_animation,":animation",":agent_no",0),#0读取agent的下身动作 1上半身
5.(agent_ai_get_num_cached_enemies, ":num", ":agent_no"), (agent_ai_get_cached_enemy, ":enemies", ":agent_no", ":index")#参考下面代码组合使用,读取agent最近的敌人
6.agent_ai_get_move_target、agent_ai_get_look_target#获得agent移向的目标或者观察的目标
7.(agent_set_position, ":agent_no", pos51),#强制移动agent
8. (agent_get_team,":agent_team",":agent_no"),(agent_get_division, ":agent_division", ":agent_no"), (team_get_movement_order, ":movement_order", ":agent_team", ":agent_division"),#组合获得agent的队伍移动命令
三、代码思路:
1.直接通过agent的当前动作来强制位移,不涉及修改原来的骑砍AI;
2.根据实际效果,因(agent_set_no_dynamics, ":agent_no", 1),会造成穿模异常,当飞行agent接近目标agent,如果目标agent是地面需要取消飞行状态,目标agent是飞行状态则限制agent前进。
3.通过读取agent_is_in_line_of_sight来判断场景阻挡,通过判断飞行agent的周围其他agent来判断是否有其他敌方agent阻挡。
四、代码
(一)、script部分
- #检查agent是是飞行单位
- ("cf_agent_is_fly", [
- (store_script_param, ":agent_no", 1),
-
- (gt,":agent_no",-1),
- (agent_slot_ge,":agent_no",slot_agent_fly,1),
- ]),
-
- #检查agent是不是飞行单位
- ("cf_agent_is_no_fly", [
- (store_script_param, ":agent_no", 1),
-
- (gt,":agent_no",-1),
- (neg|agent_slot_ge,":agent_no",slot_agent_fly,1),
- ]),
-
-
-
-
- #判断agent前方是否有其他agent阻挡
- ("cf_agent_go_forward_be_hindered_from_other_agent",
- [
- (store_script_param, ":agent_no", 1),
- (store_script_param, ":is_run", 2),
- (gt,":agent_no",-1),
- (agent_is_alive,":agent_no"),
- (agent_is_human,":agent_no"),
- (agent_get_team,":team",":agent_no"),
- (init_position,pos30),
- (agent_get_position,pos30,":agent_no"),
- (agent_get_horse,":horse",":agent_no"),
- (assign,":radius_fixed_point",200),
- (assign,":z_value_p",150),
- (try_begin),
- (gt,":horse",-1),
- (assign,":z_value_p",300),
- (try_end),
- (store_mul,":z_value_n",":z_value_p",-1),
-
- (assign,":be_hindered",0),
- (try_for_agents,":other_agent",pos30,":radius_fixed_point"),
- (eq,":be_hindered",0),
- (neq,":other_agent",":agent_no"),
- (agent_is_alive,":other_agent"),
- (agent_is_human,":other_agent"),
- (agent_get_team,":other_team",":other_agent"),
- (teams_are_enemies,":other_team",":team"),
-
- (agent_get_horse,":other_agent_horse",":other_agent"),
- (assign,":x_value_p",30),
-
- (assign,":distance_value",50),
- (try_begin),
- (gt,":other_agent_horse",-1),
- (assign,":x_value_p",100),
- (assign,":distance_value",100),
- (try_end),
- (store_mul,":x_value_n",":x_value_p",-1),
- #骑马加上马头和人的距离
- (try_begin),
- (gt,":horse",-1),
- (val_add,":distance_value",100),
- (try_end),
-
- (init_position,pos31),
- (agent_get_position,pos31,":other_agent"),
- (get_distance_between_positions,":distance",pos31,pos30),
- (init_position,pos32),
- (position_transform_position_to_local,pos32,pos30,pos31),
- (position_get_x,":x_0",pos32),
- (position_get_y,":y_0",pos32),
- (position_get_z,":z_0",pos32),
- (gt,":y_0",0),
- (le,":distance",":distance_value"),
- (is_between,":z_0",":z_value_n",":z_value_p"),
- (is_between,":x_0",":x_value_n",":x_value_p"),
- (assign,":be_hindered",1),
- (try_end),
-
- (eq,":be_hindered",":is_run"),
- ]
- ),
-
- #判断agent后退是否有其他agent阻挡
- ("cf_agent_go_back_be_hindered_from_other_agent",
- [
- (store_script_param, ":agent_no", 1),
- (store_script_param, ":is_run", 2),
- (gt,":agent_no",-1),
- (agent_is_alive,":agent_no"),
- (agent_is_human,":agent_no"),
- (agent_get_team,":team",":agent_no"),
- (init_position,pos30),
- (agent_get_position,pos30,":agent_no"),
- (agent_get_horse,":horse",":agent_no"),
- (assign,":radius_fixed_point",200),
- (assign,":z_value_p",150),
- (try_begin),
- (gt,":horse",-1),
- (assign,":z_value_p",300),
- (try_end),
- (store_mul,":z_value_n",":z_value_p",-1),
-
- (assign,":be_hindered",0),
- (try_for_agents,":other_agent",pos30,":radius_fixed_point"),
- (eq,":be_hindered",0),
- (neq,":other_agent",":agent_no"),
- (agent_is_alive,":other_agent"),
- (agent_is_human,":other_agent"),
- (agent_get_team,":other_team",":other_agent"),
- (teams_are_enemies,":other_team",":team"),
-
- (agent_get_horse,":other_agent_horse",":other_agent"),
- (assign,":x_value_p",30),
-
- (assign,":distance_value",50),
- (try_begin),
- (gt,":other_agent_horse",-1),
- (assign,":x_value_p",100),
- (assign,":distance_value",100),
- (try_end),
- (store_mul,":x_value_n",":x_value_p",-1),
-
- (try_begin),
- (gt,":horse",-1),
- (val_add,":distance_value",100),
- (try_end),
-
- (init_position,pos31),
- (agent_get_position,pos31,":other_agent"),
- (get_distance_between_positions,":distance",pos31,pos30),
- (init_position,pos32),
- (position_transform_position_to_local,pos32,pos30,pos31),
- (position_get_x,":x_0",pos32),
- (position_get_y,":y_0",pos32),
- (position_get_z,":z_0",pos32),
- (lt,":y_0",0),
- (le,":distance",":distance_value"),
- (is_between,":z_0",":z_value_n",":z_value_p"),
- (is_between,":x_0",":x_value_n",":x_value_p"),
- (assign,":be_hindered",1),
- (try_end),
-
- (eq,":be_hindered",":is_run"),
- ]
- ),
- #判断agent右边是否有其他agent阻挡
- ("cf_agent_go_right_be_hindered_from_other_agent",
- [
-
- (store_script_param, ":agent_no", 1),
- (store_script_param, ":is_run", 2),
- (gt,":agent_no",-1),
- (agent_is_alive,":agent_no"),
- (agent_is_human,":agent_no"),
- (agent_get_team,":team",":agent_no"),
- (init_position,pos30),
- (agent_get_position,pos30,":agent_no"),
- (agent_get_horse,":horse",":agent_no"),
- (assign,":radius_fixed_point",200),
- (assign,":z_value_p",150),
- (try_begin),
- (gt,":horse",-1),
- (assign,":z_value_p",300),
- (try_end),
- (store_mul,":z_value_n",":z_value_p",-1),
-
- (assign,":be_hindered",0),
- (try_for_agents,":other_agent",pos30,":radius_fixed_point"),
- (eq,":be_hindered",0),
- (neq,":other_agent",":agent_no"),
- (agent_is_alive,":other_agent"),
- (agent_is_human,":other_agent"),
- (agent_get_team,":other_team",":other_agent"),
- (teams_are_enemies,":other_team",":team"),
-
- (agent_get_horse,":other_agent_horse",":other_agent"),
- (assign,":y_value_p",30),
-
- (assign,":distance_value",50),
- (try_begin),
- (gt,":other_agent_horse",-1),
- (assign,":y_value_p",100),
- (assign,":distance_value",100),
- (try_end),
- (store_mul,":y_value_n",":y_value_p",-1),
- #骑马加上马头和人的距离
- (try_begin),
- (gt,":horse",-1),
- (val_add,":distance_value",100),
- (try_end),
-
- (init_position,pos31),
- (agent_get_position,pos31,":other_agent"),
- (get_distance_between_positions,":distance",pos31,pos30),
- (init_position,pos32),
- (position_transform_position_to_local,pos32,pos30,pos31),
- (position_get_x,":x_0",pos32),
- (position_get_y,":y_0",pos32),
- (position_get_z,":z_0",pos32),
- (gt,":x_0",0),
- (le,":distance",":distance_value"),
- (is_between,":z_0",":z_value_n",":z_value_p"),
- (is_between,":y_0",":y_value_n",":y_value_p"),
- (assign,":be_hindered",1),
- (try_end),
-
- (eq,":be_hindered",":is_run"),
-
- ]
- ),
- #判断agent左边是否有其他agent阻挡
- ("cf_agent_go_left_be_hindered_from_other_agent",
- [
- (store_script_param, ":agent_no", 1),
- (store_script_param, ":is_run", 2),
- (gt,":agent_no",-1),
- (agent_is_alive,":agent_no"),
- (agent_is_human,":agent_no"),
- (agent_get_team,":team",":agent_no"),
- (init_position,pos30),
- (agent_get_position,pos30,":agent_no"),
- (agent_get_horse,":horse",":agent_no"),
- (assign,":radius_fixed_point",200),
- (assign,":z_value_p",150),
- (try_begin),
- (gt,":horse",-1),
- (assign,":z_value_p",300),
- (try_end),
- (store_mul,":z_value_n",":z_value_p",-1),
-
- (assign,":be_hindered",0),
- (try_for_agents,":other_agent",pos30,":radius_fixed_point"),
- (eq,":be_hindered",0),
- (neq,":other_agent",":agent_no"),
- (agent_is_alive,":other_agent"),
- (agent_is_human,":other_agent"),
- (agent_get_team,":other_team",":other_agent"),
- (teams_are_enemies,":other_team",":team"),
-
- (agent_get_horse,":other_agent_horse",":other_agent"),
- (assign,":y_value_p",30),
-
- (assign,":distance_value",50),
- (try_begin),
- (gt,":other_agent_horse",-1),
- (assign,":y_value_p",100),
- (assign,":distance_value",100),
- (try_end),
- (store_mul,":y_value_n",":y_value_p",-1),
- #骑马加上马头和人的距离
- (try_begin),
- (gt,":horse",-1),
- (val_add,":distance_value",100),
- (try_end),
-
- (init_position,pos31),
- (agent_get_position,pos31,":other_agent"),
- (get_distance_between_positions,":distance",pos31,pos30),
- (init_position,pos32),
- (position_transform_position_to_local,pos32,pos30,pos31),
- (position_get_x,":x_0",pos32),
- (position_get_y,":y_0",pos32),
- (position_get_z,":z_0",pos32),
- (lt,":x_0",0),
- (le,":distance",":distance_value"),
- (is_between,":z_0",":z_value_n",":z_value_p"),
- (is_between,":y_0",":y_value_n",":y_value_p"),
- (assign,":be_hindered",1),
- (try_end),
-
- (eq,":be_hindered",":is_run"),
- ]
- ),
复制代码
(二)module_mission_templates部分玩家使用Y进入飞行,接触地面自动接触
- init_the_key_y = (
-
- 0,0,2,[
- (key_clicked,key_y),
- (get_player_agent_no, ":player_agent"),
- (neg|agent_slot_ge,":player_agent",slot_agent_fly,1),#非飞行
- ],
- [
- (set_fixed_point_multiplier, 100),
-
- (get_player_agent_no, ":player_agent"),
- (agent_get_horse,":horse", ":player_agent"),
- (agent_get_position, pos10, ":player_agent"),
-
- (try_begin),
- (gt,":horse",-1),
- (assign,":var_0",":horse"),
- (else_try),
- (assign,":var_0",":player_agent"),
- (try_end),
- (position_move_z,pos10,10),
- (agent_set_slot,":player_agent",slot_agent_fly,1),#飞行
- (agent_set_no_dynamics, ":var_0", 1),
- (agent_set_position,":var_0",pos10),
- (display_message,"@player fly is on"),
-
- ]
- )
- common_player_fly = (0.0,0,0,
- [
- (get_player_agent_no, ":player_agent"),
- (agent_slot_ge, ":player_agent", slot_agent_fly, 1),
- ],
- [
- (set_fixed_point_multiplier, 100),
-
- (get_player_agent_no, ":player_agent"),
- (assign,":y_move",0),
- (assign,":x_move",0),
- (assign,":z_move",0),
- (init_position,pos5),
- #骑马的时候马与人共用速度
- (agent_get_horse, ":horse", ":player_agent"),
- (assign,":var_0",":player_agent"),
- (try_begin),
- (gt,":horse",-1),
- (assign,":var_0",":horse"),
- (try_end),
- (agent_get_speed,pos5,":var_0"),
- (position_get_y,":y_speed",pos5),
- (position_get_x,":x_speed",pos5),
-
- (try_begin),
- (gt,":horse",-1),
- (store_div,":y_move",":y_speed",fly_y_horse_move_div),
- (store_div,":x_move",":x_speed",fly_x_horse_move_div),
- (else_try),
- (store_div,":y_move",":y_speed",fly_y_move_div),
- (store_div,":x_move",":x_speed",fly_x_move_div),
- (try_end),
-
- (init_position,pos6),
- (agent_get_look_position, pos6, ":player_agent"),
- (position_get_rotation_around_x, ":rotation_x_player", pos6),
- (try_begin),
- (key_is_down, key_v),
- (assign,":z_move",z_move_up),
- (else_try),
- (key_is_down, key_b),
- (assign,":z_move",z_move_up),
- (val_mul,":z_move",-1),
- (else_try),
- (neq,":y_move",0),
- (is_between,":rotation_x_player",1,91),#鼠标移动玩家视角向上 对着天空
- (store_div,":value", ":rotation_x_player",9),
- (val_add,":value",1),
- (store_div,":z_move",":y_move",fly_z_move_div),
- (val_mul,":z_move",":value"),
- (else_try),
- (neq,":y_move",0),
- (is_between,":rotation_x_player",270,360),#鼠标移动玩家视角向下 对着地面
- (store_sub,":value", 360,":rotation_x_player"),
- (store_div,":value", ":value",9),
- (val_add,":value",1),
- (val_mul,":value",-1),
- (store_div,":z_move",":y_move",fly_z_move_div),
- (val_mul,":z_move",":value"),
- (try_end),
-
- #其他agnt阻挡
- (assign,":be_block",0),
- (try_begin),
- (gt,":y_move",0),
- (call_script,"script_cf_agent_go_forward_be_hindered_from_other_agent",":player_agent",1),
- (assign,":be_block",1),
- (else_try),
- (lt,":y_move",0),
- (call_script,"script_cf_agent_go_back_be_hindered_from_other_agent",":player_agent",1),
- (assign,":be_block",1),
- (else_try),
- (gt,":x_move",0),
- (call_script,"script_cf_agent_go_right_be_hindered_from_other_agent",":player_agent",1),
- (assign,":be_block",1),
- (else_try),
- (lt,":x_move",0),
- (call_script,"script_cf_agent_go_left_be_hindered_from_other_agent",":player_agent",1),
- (assign,":be_block",1),
- (try_end),
- (eq,":be_block",0),
- ##
-
- (init_position,pos5),
- (agent_get_position,pos5,":var_0"),
- #限制飞行高度
- (position_get_z,":pos_z",pos5),
- (try_begin),
- (ge,":pos_z",fly_z_height_limit),
- (gt,":z_move",0),
- (assign,":z_move",0),
- (try_end),
- ##
-
- #使用武器时候Z轴不移动
- (try_begin),
- (agent_get_attack_action, ":attack_action", ":player_agent"),
- (neq, ":attack_action",0),
- (assign,":z_move",0),
- (try_end),
- ##
-
- (neq|this_or_next,":y_move",0),
- (neq|this_or_next,":x_move",0),
- (neq,":z_move",0),
- (position_move_y,pos5,":y_move"),
- (position_move_x,pos5,":x_move"),
- (position_move_z,pos5,":z_move"),
- (try_begin),
- (game_key_is_down,gk_move_right),
- (position_rotate_z, pos5,-1),
- (else_try),
- (game_key_is_down,gk_move_left),
- (position_rotate_z, pos5, 1),
- (try_end),
-
- #获得地图最大限制
- (get_scene_boundaries, pos26, pos27),#左下角和右上角的点,方向朝上
- (position_get_x, ":lower_left_corner_x", pos26),
- (position_get_y, ":lower_left_corner_y", pos26),
- (position_get_x, ":upper_right_corner_x", pos27),
- (position_get_y, ":upper_right_corner_y", pos27),
- (val_add,":lower_left_corner_x",50),
- (val_add,":lower_left_corner_y",50),
- (val_sub,":upper_right_corner_x",50),
- (val_sub,":upper_right_corner_y",50),
-
-
- #设置障碍判断pos6
- (init_position,pos6),
- (copy_position ,pos6,pos5),
- (try_begin),
- (gt,":horse",-1),
- (position_move_z, pos6, 300),
- (position_move_y, pos6, 200),
- (else_try),
- (position_move_z, pos6, 150),
- (position_move_y, pos6, 100),
- (try_end),
- #读取xy数据与对地面距离
- (position_get_x,":pos_x",pos5),
- (position_get_y,":pos_y",pos5),
- (position_get_distance_to_ground_level,":ground_level",pos5),
- (try_begin),#接触地面退出飞行
- (le,":ground_level",0),
- (agent_set_slot,":player_agent",slot_agent_fly,0),#退出飞行
- (agent_set_no_dynamics, ":var_0", 0),
- (display_message,"@player fly is off"),
- (else_try),
- #防止飞出地图
- (gt,":pos_x",":lower_left_corner_x"),
- (lt,":pos_x",":upper_right_corner_x"),
- (gt,":pos_y",":lower_left_corner_y"),
- (lt,":pos_y",":upper_right_corner_y"),
- #判断前方障碍点
- (agent_is_in_line_of_sight,":player_agent",pos6),
- (agent_set_position,":var_0",pos5),
- (try_end),
-
- ])
- common_agent_flying_lead_charge = (0, 0, 0, [],
- [
- #设置pos单位量尺为cm
- (set_fixed_point_multiplier, 100),
-
- (try_for_agents, ":agent_no"),
- (agent_is_non_player,":agent_no"),
- (agent_is_human, ":agent_no"), ##是人
- (agent_is_alive, ":agent_no"), ##存活的
- (neg|agent_is_wounded,":agent_no"),##非击晕的
- (agent_get_troop_id,":troop_id",":agent_no"),
- (agent_get_horse,":horse", ":agent_no"),
- (agent_get_team,":agent_team",":agent_no"),
- (agent_get_division, ":agent_division", ":agent_no"),
- (team_get_movement_order, ":movement_order", ":agent_team", ":agent_division"),
-
- (assign,":agent_can_fly",0),
- (try_begin),
- (gt,":horse",-1),
- (agent_get_item_id,":item_id",":horse"),
- (eq,":item_id","itm_courser_fly"),
- (assign,":agent_can_fly",1),
- (else_try),
- (this_or_next|eq,":troop_id","trp_nord_champion_fly"),#需要设定的单位
- (eq,":troop_id","trp_swadian_sharpshooter_fly"),
- (assign,":agent_can_fly",1),
- (try_end),
-
- (eq,":agent_can_fly",1),
-
- ##强制设定目标
- (agent_ai_get_move_target,":target_agent",":agent_no"),
- (try_begin),
- (lt,":target_agent",0),
- (agent_ai_get_look_target,":target_agent",":agent_no"),
- (try_begin),
- (gt,":target_agent",-1),
- (agent_is_alive,":target_agent"),
- (else_try),
- (agent_clear_scripted_mode, ":agent_no"),
- (agent_ai_get_num_cached_enemies, ":num", ":agent_no"),
- (try_for_range,":index",0,":num"),#get target_agent
- (store_random_in_range,":index",0,":num"),
- (agent_ai_get_cached_enemy, reg40,":agent_no",":index"),
- (agent_is_alive, reg40),
- (assign,":target_agent",reg40),
- (agent_set_look_target_agent,":agent_no",":target_agent"),
- (assign,":num",-1),#break
- (try_end),
- (try_end),
- (try_end),
- ##
- #设定var_0
- (try_begin),
- (gt,":horse",-1),
- (assign,":var_0",":horse"),
- (else_try),
- (assign,":var_0",":agent_no"),
- (try_end),
- ##
-
- (try_begin),#开始飞行
- (neg|agent_slot_ge,":agent_no",slot_agent_fly,1),#非飞行
- (eq, ":movement_order", mordr_charge),
- (gt,":target_agent",-1),
- #获得目标target_agent与agent_no的距离
- (init_position,pos20),
- (agent_get_position, pos20, ":agent_no"),
- (init_position,pos21),
- (agent_get_position, pos21, ":target_agent"),
- (get_distance_between_positions,":distance_target",pos20,pos21),
-
- (try_begin),
- (gt,":horse",-1),
- (assign,":var_0",":horse"),
- (position_move_z,pos20,z_move_up),
- (assign,":distance_target_judgment",5000),
- (else_try),
- (assign,":var_0",":agent_no"),
- (position_move_z,pos20,z_move_up),
- (assign,":distance_target_judgment",2500),
- (try_end),
- #距离满足或target_agent是飞行状态则进入飞行状态
- (assign,":agent_start_fly",0),
- (try_begin),
- (agent_slot_ge,":target_agent",slot_agent_fly,1),#飞行
- (assign,":agent_start_fly",1),
- (else_try),
- (gt,":distance_target",":distance_target_judgment"),
- (assign,":agent_start_fly",1),
- (try_end),
- ##
- (eq,":agent_start_fly",1),
- (agent_set_slot,":agent_no",slot_agent_fly,1),
- (agent_set_no_dynamics, ":var_0", 1),
- (agent_set_position, ":var_0", pos20),
- (else_try),#起飞飞行
- (agent_slot_eq,":agent_no",slot_agent_fly,1),
- (init_position,pos20),
- (agent_get_position, pos20, ":agent_no"),
- (position_get_distance_to_ground_level,":ground_level",pos20),
- (try_begin),
- (le, ":ground_level",1000),
- (position_move_z,pos20,z_move_up),
- (agent_set_position, ":var_0", pos20),
- (else_try),
- (agent_set_slot,":agent_no",slot_agent_fly,2),
- (try_end),
- (else_try),#正常飞行
- (agent_slot_eq,":agent_no",slot_agent_fly,2),
- (assign,":y_move",0),
- (assign,":x_move",0),
- (assign,":z_move",0),
-
- (init_position,pos20),
- (agent_get_speed,pos20,":var_0"),
- (position_get_y,":y_speed",pos20),
- (position_get_x,":x_speed",pos20),
- #速度
- (try_begin),
- (gt,":horse",-1),
- (val_div,":y_speed",fly_y_horse_move_div),
- (assign,":y_move",":y_speed"),
- (val_div,":x_speed",fly_x_horse_move_div),
- (assign,":x_move",":x_speed"),
- (else_try),
- (val_div,":y_speed",fly_y_move_div),
- (assign,":y_move",":y_speed"),
- (val_div,":x_speed",fly_x_move_div),
- (assign,":x_move",":x_speed"),
- (try_end),
- (init_position,pos20),
- (agent_get_look_position, pos20, ":agent_no"),
- (position_get_rotation_around_x, ":rotation_x", pos20),
- (try_begin),
- (neq,":y_move",0),
- (is_between,":rotation_x",1,91),#鼠标移动玩家视角向上 对着天空
- (store_div,":value", ":rotation_x",9),
- (val_add,":value",1),
- (store_div,":z_move",":y_move",fly_z_move_div),
- (val_mul,":z_move",":value"),
- (else_try),
- (neq,":y_move",0),
- (is_between,":rotation_x",270,360),#鼠标移动玩家视角向下 对着地面
- (store_sub,":value", 360,":rotation_x"),
- (store_div,":value", ":value",9),
- (val_add,":value",1),
- (val_mul,":value",-1),
- (store_div,":z_move",":y_move",fly_z_move_div),
- (val_mul,":z_move",":value"),
- (try_end),
- #其他agnt阻挡
- (assign,":be_block",0),
- (try_begin),
- (gt,":y_move",0),
- (call_script,"script_cf_agent_go_forward_be_hindered_from_other_agent",":agent_no",1),
- (assign,":be_block",1),
- (else_try),
- (lt,":y_move",0),
- (call_script,"script_cf_agent_go_back_be_hindered_from_other_agent",":agent_no",1),
- (assign,":be_block",1),
- (else_try),
- (gt,":x_move",0),
- (call_script,"script_cf_agent_go_right_be_hindered_from_other_agent",":agent_no",1),
- (assign,":be_block",1),
- (else_try),
- (lt,":x_move",0),
- (call_script,"script_cf_agent_go_left_be_hindered_from_other_agent",":agent_no",1),
- (assign,":be_block",1),
- (try_end),
- (eq,":be_block",0),
- ##
- ##AI条件限制防止一直向下
- (try_begin),
- (gt,":y_move",0),
- (lt,":z_move",0),
- (gt,":target_agent",0),
- (neg|agent_slot_ge,":target_agent",slot_agent_fly,1),#非飞行
- (eq, ":movement_order", mordr_charge),
- #获得目标target_agent与agent_no的距离
- (init_position,pos21),
- (agent_get_position, pos21, ":target_agent"),
- (get_distance_between_positions,":distance_target",pos20,pos21),
- #对应非飞行单位根据距离下降,进入一定范围后才下降
- (try_begin),
- (gt,":horse",0),
- (gt,":distance_target",1500),
- (assign,":z_move",0),
- (else_try),
- (gt,":distance_target",750),
- (assign,":z_move",0),
- (try_end),
- (try_end),
- ##
- (neq|this_or_next,":y_move",0),
- (neq|this_or_next,":x_move",0),
- (neq,":z_move",0),
-
- (init_position,pos20),
- (agent_get_position,pos20,":var_0"),
- #限制飞行高度
- (position_get_z,":pos_z",pos20),
- (try_begin),
- (ge,":pos_z",fly_z_height_limit),
- (gt,":z_move",0),
- (assign,":z_move",0),
- (try_end),
- ##
-
- #使用武器时候Z轴不移动
- (try_begin),
- (agent_get_attack_action, ":attack_action", ":agent_no"),
- (neq, ":attack_action",0),
- (assign,":z_move",0),
- (try_end),
- ##
-
- (init_position,pos19),
- (copy_position ,pos19,pos20),
- (position_move_y,pos20,":y_move"),
- (position_move_x,pos20,":x_move"),
- (position_move_z,pos20,":z_move"),
-
- ##骑手马的转动 读取马的动作来作为依据
- (try_begin),
- (gt,":horse",-1),
- (agent_get_animation,":animation",":horse",1),#必须是1读取上半身!!!!!!!!!
- (try_begin),
- (eq|this_or_next,":animation","anim_horse_turn_right"),
- (eq,":animation","anim_horse_turn_right_head"),
- (position_rotate_z, pos20,-1),
- (else_try),
- (eq|this_or_next,":animation","anim_horse_turn_left"),
- (eq,":animation","anim_horse_turn_left_head"),
- (position_rotate_z, pos20, 1),
- (try_end),
- (try_end),
- ##
- #获得地图最大限制
- (init_position,pos26),
- (init_position,pos27),
- (get_scene_boundaries, pos26, pos27),#左下角和右上角的点,方向朝上
- (position_get_x, ":lower_left_corner_x", pos26),
- (position_get_y, ":lower_left_corner_y", pos26),
- (position_get_x, ":upper_right_corner_x", pos27),
- (position_get_y, ":upper_right_corner_y", pos27),
- (val_add,":lower_left_corner_x",50),
- (val_add,":lower_left_corner_y",50),
- (val_sub,":upper_right_corner_x",50),
- (val_sub,":upper_right_corner_y",50),
-
- #设置障碍判断pos21
- (init_position,pos21),
- (copy_position ,pos21,pos20),
- (try_begin),
- (gt,":horse",-1),
- (position_move_z, pos21, 300),
- (position_move_y, pos21, 200),
- (else_try),
- (position_move_z, pos21, 150),
- (position_move_y, pos21, 100),
- (try_end),
-
- #读取xy数据与对地面距离
- (position_get_x,":pos_x",pos20),
- (position_get_y,":pos_y",pos20),
- (position_get_distance_to_ground_level,":ground_level",pos20),
- (try_begin),#接触地面退出飞行
- (le,":ground_level",0),
- (agent_set_slot,":agent_no",slot_agent_fly,0),#退出飞行
- (agent_set_no_dynamics, ":var_0", 0),
- (else_try),#判断前方障碍点
- (neg|agent_is_in_line_of_sight,":agent_no",pos21),
- (position_move_z,pos19,10),
- (agent_set_position,":var_0",pos19),
- (else_try),
- #防止飞出地图
- (gt,":pos_x",":lower_left_corner_x"),
- (lt,":pos_x",":upper_right_corner_x"),
- (gt,":pos_y",":lower_left_corner_y"),
- (lt,":pos_y",":upper_right_corner_y"),
- (agent_set_position,":var_0",pos20),
- (try_end),
- (try_end),
- (try_end),
- ]
- )
复制代码
(三)常量部分
- z_move_up = 10
- fly_y_move_div = 10
- fly_x_move_div = 10
- fly_z_move_div = 4
- fly_y_horse_move_div = 40
- fly_x_horse_move_div = 30
- fly_z_horse_move_div = 4
- fly_z_height_limit = 5000
- #agent是否处于飞行状态
- slot_agent_fly = 100
复制代码
(四)、效果
视频展示:
骑马与砍杀战团飞砍,是兄弟就来飞砍_哔哩哔哩bilibili_骑马与砍杀_演示
骑马与砍杀战团飞砍,是兄弟就来飞砍_哔哩哔哩bilibili_骑马与砍杀_演示
|