master
chendian 2 years ago
parent eff5db72a9
commit 32491ae75d

File diff suppressed because one or more lines are too long

@ -24,6 +24,7 @@ shader_parameter/deformation_rate = 0.0
shader_parameter/tex = ExtResource("4_fcd8a") shader_parameter/tex = ExtResource("4_fcd8a")
[node name="Character" type="CharacterBody3D"] [node name="Character" type="CharacterBody3D"]
collision_layer = 512
script = ExtResource("1_tonbs") script = ExtResource("1_tonbs")
[node name="Collision" type="CollisionShape3D" parent="."] [node name="Collision" type="CollisionShape3D" parent="."]

@ -18,6 +18,12 @@ func vector_reduce(vector:Vector2,reduce:float) -> Vector2:
var scale_rate = new_len / len var scale_rate = new_len / len
return vector * scale_rate return vector * scale_rate
func raycast_wall(from:Vector3,to:Vector3) -> bool:
var space_state = get_world_3d().direct_space_state
var query = PhysicsRayQueryParameters3D.create(from,to,1)
var result = space_state.intersect_ray(query)
return result.size()>0
func refresh_animation_lib(): func refresh_animation_lib():
var animation_library_path = "res://resource/skill_animation_library/animation_library.tres" var animation_library_path = "res://resource/skill_animation_library/animation_library.tres"
var animation_library = load(animation_library_path) var animation_library = load(animation_library_path)

@ -40,6 +40,24 @@ func init_after():
func set_material(material:ShaderMaterial): func set_material(material:ShaderMaterial):
view.material_override = material view.material_override = material
func is_on_stair()->bool:
if velocity.x > 0:
if raycast_stair(Vector3.RIGHT):return true
elif velocity.x < 0:
if raycast_stair(Vector3.LEFT):return true
if velocity.z > 0:
if raycast_stair(Vector3.BACK):return true
elif velocity.z < 0:
if raycast_stair(Vector3.FORWARD):return true
return false
func raycast_stair(dir:Vector3)->bool:
var width = Setting.pixel_size * status.cfg.sprite_width
var from = position + Vector3.UP * Setting.pixel_size * 6 + dir * width * 0.4
var to = from + dir * width * 0.2
var up = to + Vector3.UP * Setting.pixel_size * 4
return Util.raycast_wall(from,to) and Util.raycast_wall(up,to)
#==getter== #==getter==
func id()->int:return status.id func id()->int:return status.id
func cfg()->CharacterCfg:return status.cfg func cfg()->CharacterCfg:return status.cfg

@ -11,8 +11,8 @@ func _process(delta):
if Global.is_level_loading_contorl:return if Global.is_level_loading_contorl:return
if status.is_pause:return if status.is_pause:return
var is_hit_floor = update_on_floor(delta) var is_hit_floor = update_on_floor(delta)
update_speed_y(delta)
update_move(delta) update_move(delta)
update_speed_y(delta)
character.move_and_slide() character.move_and_slide()
if character.velocity: if character.velocity:
SignalManager.character_pos_changed.emit(character.id(),character.pos()) SignalManager.character_pos_changed.emit(character.id(),character.pos())
@ -31,8 +31,12 @@ func update_on_floor(delta) -> bool:
func update_speed_y(delta): func update_speed_y(delta):
var has_y_speed = status.skill_float_speed != 0 or status.hit_up_speed != 0 var has_y_speed = status.skill_float_speed != 0 or status.hit_up_speed != 0
var is_on_stair = character.is_on_stair()
if has_y_speed: if has_y_speed:
character.velocity.y = status.skill_float_speed + status.hit_up_speed character.velocity.y = status.skill_float_speed + status.hit_up_speed
else:
if is_on_stair:
character.velocity.y = status.cfg.move.speed * 0.75
else: else:
if not status.is_on_floor: if not status.is_on_floor:
character.velocity.y -= gravity * delta * status.cfg.move.gravity_scale character.velocity.y -= gravity * delta * status.cfg.move.gravity_scale

Loading…
Cancel
Save