本帖最后由 杰喵喵 于 2023-8-28 22:42 编辑
一、效果概述与展示
1.按Y按键腾空进入飞行状态,飞行状态下贴近地面自动退出飞行;
2.飞行状态下,人的飞行操作与原来一样,视角对着天空前进升高飞行高度,对着地面前进降低飞行高度。骑马飞行情况下,非骑射状态下视角对着天空前进升高飞行高度,对着地面降低飞行高度;骑射状态下不改变飞行高度,其余操作与地面控制一样。
效果展示:
使用场景道具辅助飞行测试_哔哩哔哩bilibili
特别鸣谢:nimoadna(《大冒险家》)的指导与解答。
二、关键概念
1.Position rotation
# Position rotation determines just that - rotation around corresponding
# world axis. So rotation around Z axis means rotation around vertical axis,
# in other words - turning right and left. Rotation around X and Y axis will
# tilt the position forward/backwards and right/left respectively.
简单来说,agent的Position默认Y轴是前进后,X轴左右移动,Z轴上下移动,Position rotation就是沿着这些轴旋转。
2.场景道具销毁
似乎没有绝对消除的办法,我这里使用场景隐身与关闭物理来解决。 (prop_instance_enable_physics,":borad",0),#关闭碰撞体 (scene_prop_set_visibility,":borad",0), #关闭显示
3.使用与下次飞行位置的Z轴-1垂直点,通过 position_set_z_to_ground_level 来用于是否接触地面判断。因为玩家始终在托板上面,使用玩家位置点来position_get_distance_to_ground_level 始终大于等于0。具体实现看下面程序。
3.position_get_distance_to_terrain,pos对地形的距离负数表示在地形之下,正数在地形之上。
4.城墙或者其他场景上降落使用
(cast_ray, <destination>, <hit_position_register>, <ray_position_register>, [<ray_length_fixed_point>]),
强制转换一条长度为[<ray_length_fixed_point>]的射线,从<ray_position_register>开始,并将最近的命中位置存储到<hit_position_register>中(如果没有命中则失败)。如果body hit是一个prop实例,它的id将被存储到<destination>中。
简单来说就是将agent的位置点往下移动,绕X轴旋转 90度,然后发射判断线,如果有碰撞到非踏板的其他场景单位,则取消飞行。
5.退出飞行直接将踏板埋在底下。
三、代码
slot_agent_fly 飞行状态标志位
slot_agent_fly_borad 存储飞行道具的ID
- init_the_key_y = (
-
- 0,0,2,[
- (key_clicked,key_y),
- ],
- [
- (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"),
- (position_move_z,pos10,50),
- (else_try),
- (assign,":var_0",":player_agent"),
- (position_move_z,pos10,25),
- (try_end),
-
- (agent_get_slot,":borad",":player_agent",slot_agent_fly_borad),
-
- (try_begin),
- (le,":borad",0),
- (display_message,"@player fly is on"),
- #产生床
- (set_spawn_position, pos10),
- (try_begin),
- (gt,":horse",-1),
- (spawn_scene_prop, "spr_bed_a_new"),
- (else_try),
- (spawn_scene_prop, "spr_pillow_a_new"),
- (try_end),
- (assign,":borad",reg0),
- (agent_set_slot,":player_agent",slot_agent_fly_borad,":borad"),
- (display_message,"@spawn bed"),
- (agent_set_slot,":player_agent",slot_agent_fly,1),
- (agent_set_position, ":var_0", pos10),
- (prop_instance_enable_physics,":borad",1),#碰撞体
- (scene_prop_set_visibility,":borad",my_prop_set_visibility), #显示
- (else_try),
- (prop_instance_enable_physics,":borad",1),#碰撞体
-
- #限制角度保护 X Y 轴rotation
- (position_get_rotation_around_x, ":rotation_x", pos10),
- (position_get_rotation_around_y, ":rotation_y", pos10),
-
- (try_begin),
- (gt,":rotation_x",0),
- (store_sub,":angle_x",":rotation_x",0),
- (val_mul,":angle_x",-1),
- (position_rotate_x,pos10,":angle_x"),
- (else_try),
- (lt,":rotation_x",360),
- (store_sub,":angle_x",360,":rotation_x"),
- (position_rotate_x,pos10,":angle_x"),
- (try_end),
-
- (try_begin),
- (gt,":rotation_y",0),
- (store_sub,":angle_y",":rotation_y",0),
- (val_mul,":angle_y",-1),
- (position_rotate_y,pos10,":angle_y"),
- (else_try),
- (lt,":rotation_y",360),
- (store_sub,":angle_y",360,":rotation_y"),
- (position_rotate_y,pos10,":angle_y"),
- (try_end),
-
- (prop_instance_set_position, ":borad", pos10),
- (agent_set_slot,":player_agent",slot_agent_fly,1),
- (agent_set_position, ":var_0", pos10),
- (try_end),
-
- ]
- )
- common_player_fly = (0.0, 0.000000, 0.000000,
- [
- (get_player_agent_no, ":player_agent"),
- (agent_get_slot,":borad",":player_agent",slot_agent_fly_borad),
- (gt,":borad",0),
- (agent_slot_eq,":player_agent",slot_agent_fly,1),
- ],
- [
- (set_fixed_point_multiplier, 100),
-
- (get_player_agent_no, ":player_agent"),
- (agent_get_slot,":borad",":player_agent",slot_agent_fly_borad),
-
- (agent_get_horse,":horse", ":player_agent"),
- (try_begin),
- (gt,":horse",-1),
- (assign,":var_0",":horse"),
- (else_try),
- (assign,":var_0",":player_agent"),
- (try_end),
-
- (init_position,pos4),
- (agent_get_look_position, pos4, ":player_agent"),
- (init_position,pos2),
- (prop_instance_get_position, pos2, ":borad"), #场景物的坐标,实时获取
-
- (try_begin),
- (key_is_down, key_w),
- (assign,":z_move",0),
- (assign,":y_move",0),
-
- (try_begin),
- (gt,":horse",-1),
- (agent_get_speed,pos20,":horse"),
- (position_get_y,":y_speed",pos20),
- (val_div,":y_speed",30),
- (assign,":y_move",":y_speed"),
-
- (position_get_rotation_around_x, ":rotation_x_player", pos4),
- (try_begin),
- (is_between,":rotation_x_player",1,91),#鼠标移动玩家视角向上 对着天空
- (store_div,":value", ":rotation_x_player",9),
- (val_add,":value",1),
- (store_div,":z_move",":y_speed",20),
- (val_mul,":z_move",":value"),
- (else_try),
- (is_between,":rotation_x_player",270,360),#鼠标移动玩家视角向下 对着地面
- (store_sub,":value", 360,":rotation_x_player"),
- (store_div,":value", ":value",9),
- (val_add,":value",4),
- (val_mul,":value",-1),
- (store_div,":z_move",":y_speed",20),
- (val_mul,":z_move",":value"),
- (try_end),
- #防止使用武器的时候Z轴上下移动,保证骑射水平移动
- (try_begin),
- (agent_get_attack_action, ":attack_action", ":player_agent"),
- (agent_get_defend_action, ":defend_action", ":player_agent"),
- (neq, ":attack_action",0),
- (neq, ":defend_action",0),
- (assign,":z_move",0),
- (try_end),
-
- (else_try),
- (agent_get_speed,pos20,":player_agent"),
- (position_get_y,":y_speed",pos20),
- (val_div,":y_speed",10),
- (assign,":y_move",":y_speed"),
- (try_end),
- (position_move_y, pos2, ":y_move"),
- (position_move_z, pos2, ":z_move"),
- (else_try),
- (key_is_down, key_a),
- (assign,":x_move",0),
- (assign,":y_move",0),
-
- (try_begin),
- (gt,":horse",-1),
- (agent_get_speed,pos20,":horse"),
- (position_get_y,":y_speed",pos20),
- (val_div,":y_speed",30),
- (assign,":y_move",":y_speed"),
- (position_rotate_z, pos2, 1),
- (else_try),
- (agent_get_speed,pos20,":player_agent"),
- (position_get_x,":x_speed",pos20),
- (val_div,":x_speed",10),
- (assign,":x_move",":x_speed"),
- (try_end),
-
- (position_move_x, pos2, ":x_move"),
- (position_move_y, pos2, ":y_move"),
- (else_try),
- (key_is_down, key_s),
- (assign,":y_move",0),
-
- (try_begin),
- (gt,":horse",-1),
- (agent_get_speed,pos20,":horse"),
- (position_get_y,":y_speed",pos20),
- (try_begin),
- (gt,":y_speed",0),
- (val_div,":y_speed",30),
- (assign,":y_move",":y_speed"),
- (else_try),
- (assign,":y_move",-5),
- (try_end),
- (else_try),
- (agent_get_speed,pos20,":player_agent"),
- (position_get_y,":y_speed",pos20),
- (val_div,":y_speed",10),
- (assign,":y_move",":y_speed"),
- (try_end),
-
- (position_move_y, pos2, ":y_move"),
- (else_try),
- (key_is_down, key_d),
- (assign,":x_move",0),
- (assign,":y_move",0),
-
- (try_begin),
- (gt,":horse",-1),
- (agent_get_speed,pos20,":horse"),
- (position_get_y,":y_speed",pos20),
- (val_div,":y_speed",30),
- (assign,":y_move",":y_speed"),
- (position_rotate_z, pos2, -1),
- (else_try),
- (agent_get_speed,pos20,":player_agent"),
- (position_get_x,":x_speed",pos20),
- (val_div,":x_speed",10),
- (assign,":x_move",":x_speed"),
- (try_end),
-
- (position_move_x, pos2, ":x_move"),
- (position_move_y, pos2, ":y_move"),
- (else_try),
- (key_is_down, key_v),
- (position_move_z,pos2,20),
- (else_try),
- (key_is_down, key_b),
- (position_move_z,pos2,-20),
- (try_end),
-
- #骑马情况下,玩家不跟随鼠标视角
- (try_begin),
- (gt,":horse",-1),
- (else_try),
- (position_copy_rotation,pos2,pos4),
- (position_get_rotation_around_x,":rotation_x",pos2),
- #Z轴限制保护防止,角度过大出问题
- (try_begin),
- (is_between,":rotation_x",0,91),#鼠标移动玩家视角向上 对着天空
- (try_begin),
- (gt,":rotation_x",45),
- (store_sub,":angle_x",":rotation_x",45),
- (val_mul,":angle_x",-1),
- (position_rotate_x,pos2,":angle_x"),
- (try_end),
- (else_try),
- (is_between,":rotation_x",270,360),#鼠标移动玩家视角向下 对着地面
- (try_begin),
- (lt,":rotation_x",315),
- (store_sub,":angle_x",315,":rotation_x"),
- (position_rotate_x,pos2,":angle_x"),
- (try_end),
- (try_end),
- (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),
-
- #设置障碍判断pos5
- (init_position,pos5),
- (copy_position ,pos5,pos2),
- #移动点对地形的距离负数表示在地形之下,正数在地形之上。position_get_distance_to_terrain
- (position_copy_origin ,pos6,pos2),
- (position_get_distance_to_terrain,":terrain",pos6),
- (try_begin),
- (gt,":horse",-1),
- (position_move_z, pos5, 300),
- (position_move_y, pos5, 200),
- (else_try),
- (position_move_z, pos5, 150),
- (position_move_y, pos5, 100),
- (try_end),
- #测试用点亮
- #(particle_system_burst,"psys_torch_fire_big_b",pos5,10),
- (position_get_x,":pos_x",pos2),
- (position_get_y,":pos_y",pos2),
- #确保玩家在地图限制范围内移动,,判断障碍点玩家之间拥有视野
- (try_begin),#玩家正常飞行
- #接近地面,是移动点与地面贴合,退出飞行
- (le, ":terrain", 5),
- (display_message,"@player fly is off one"),
- (assign,reg20,":borad"),
- (display_message,"@borad id {reg20}",":borad"),
- (prop_instance_enable_physics,":borad",0),#关闭碰撞体
- (agent_set_slot,":player_agent",slot_agent_fly,2),#退出飞行
- (else_try),
- (init_position,pos3),
- (init_position,pos6),
- (agent_get_position,pos3,":var_0"),
- (position_move_z,pos3,-20),
- (position_rotate_x,pos3,90),
- #(cast_ray, <destination>, <hit_position_register>, <ray_position_register>, [<ray_length_fixed_point>]),
- #强制转换一条长度为[<ray_length_fixed_point>]的射线,从<ray_position_register>开始,并将最近的命中位置存储到<hit_position_register>中(如果没有命中则失败)。如果body hit是一个prop实例,它的id将被存储到<destination>中。
- (cast_ray,":prop_id",pos6,pos3,20),
- (gt,":prop_id",-1),
- (prop_instance_get_scene_prop_kind,":prop_kind",":prop_id"),
- (neq,":prop_kind","spr_bed_a_new"),
- (neq,":prop_kind","spr_pillow_a_new"),
- (position_copy_rotation,pos6,pos2),
- (copy_position,pos2,pos6),
- (display_message,"@player fly is off two"),
- (assign,reg20,":borad"),
- (display_message,"@borad id {reg20}",":borad"),
- (prop_instance_enable_physics,":borad",0),#关闭碰撞体
- (agent_set_slot,":player_agent",slot_agent_fly,2),#退出飞行
- (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",pos5),
- (prop_instance_set_position, ":borad", pos2),
- (try_end),
-
- (prop_instance_get_position, pos2, ":borad"), #场景物的坐标,实时获取
- (agent_set_position, ":var_0", pos2),
- #退出飞行将床埋在地下
- (try_begin),
- (agent_slot_eq,":player_agent",slot_agent_fly,2),#退出飞行
- (position_set_z,pos2,-500),
- (prop_instance_set_position, ":borad", pos2),
- (try_end),
- ])
复制代码
如果有啥不足,欢迎各位大佬指正
|