Merge branch 'player'

This commit is contained in:
AleaJactaEst 2023-11-22 20:57:42 +01:00
commit 7c96038be7
24 changed files with 606 additions and 7506 deletions

View file

@ -1,16 +1,103 @@
extends AnimationTree
class_name AnimBlend
#@onready @export var movement_script : CharacterMovementComponent
@export var movement_script : CharacterMovementComponent
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _physics_process(_delta):
if !movement_script:
return
#Set Animation State
match movement_script.movement_state:
Global.MOVEMENT_STATE.none:
pass
Global.MOVEMENT_STATE.grounded: # Sol
set("parameters/InAir/blend_amount" , 0.0)
#set("parameters/TimeSeek/seek_request", 0.0)
#set("parameters/Transition/transition_request","Idle")
Global.MOVEMENT_STATE.in_air: # Air
set("parameters/InAir/blend_amount" , 1.0)
#set("parameters/InAir/transition_request","Failling")
Global.MOVEMENT_STATE.mantling: # couverture
pass
Global.MOVEMENT_STATE.ragdoll:
pass
#set("parameters/Transition/transition_request","Idle")
#set("parameters/InAir/blend_amount" , 0.5)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#if !movement_script:
# return
pass
func _physics_process__old(_delta):
if !movement_script:
return
#Set Animation State
match movement_script.movement_state:
Global.MOVEMENT_STATE.none:
pass
Global.MOVEMENT_STATE.grounded: # Sol
set("parameters/InAir/blend_amount" , 0.0)
#set("parameters/Transition/transition_request","Idle")
Global.MOVEMENT_STATE.in_air: # Air
set("parameters/InAir/blend_amount" , 1.0)
#set("parameters/InAir/transition_request","Failling")
Global.MOVEMENT_STATE.mantling: # couverture
pass
Global.MOVEMENT_STATE.ragdoll:
pass
#standing
if !movement_script.input_is_moving:
set("parameters/Transition/transition_request","Idle")
#set("parameters/VelocityDirection/Standing/transition_request","Idle")
#set("parameters/VelocityDirection/crouching/transition_request","Idle")
if movement_script.gait == Global.GAIT.walking and movement_script.input_is_moving:
set("parameters/Transition/transition_request","WalkForward")
#set("parameters/VelocityDirection/Standing/transition_request","Walk")
#set("parameters/VelocityDirection/crouching/transition_request","Walk")
if movement_script.gait == Global.GAIT.running and movement_script.input_is_moving:
set("parameters/Transition/transition_request","JogForward")
#set("parameters/VelocityDirection/Standing/transition_request","Jog")
if movement_script.gait == Global.GAIT.sprinting and movement_script.input_is_moving:
set("parameters/Transition/transition_request","Run")
#set("parameters/Execution/transition_request","Run")
#Couch/stand switch
match movement_script.stance:
Global.STANCE.standing:
set("parameters/Transition/transition_request","stand")
#set("parameters/VelocityDirection/crouch/transition_request" , "stand")
Global.STANCE.crouching:
set("parameters/Transition/transition_request","crouch")
#set("parameters/VelocityDirection/crouch/transition_request" , "crouch")
if movement_script.rotation_mode == Global.ROTATION_MODE.looking_direction or movement_script.rotation_mode == Global.ROTATION_MODE.aiming:
if movement_script.animation_is_moving_backward_relative_to_camera == false:
set("parameters/Transition/transition_request","WalkForward")
#set("parameters/VelocityDirection/WalkFB/transition_request","Forward")
#set("parameters/VelocityDirection/JogFB/transition_request","Forward")
else:
set("parameters/Transition/transition_request","Backward")
#set("parameters/VelocityDirection/WalkFB/transition_request","Backward")
#set("parameters/VelocityDirection/JogFB/transition_request","Backward")
else:
set("parameters/Transition/transition_request","WalkForward")
#set("parameters/VelocityDirection/WalkFB/transition_request","Forward")
#set("parameters/VelocityDirection/JogFB/transition_request","Forward")
#On Stopped
if !(Input.is_action_pressed("ui_up") || Input.is_action_pressed("ui_down") || Input.is_action_pressed("ui_right") || Input.is_action_pressed("ui_left")) and (Input.is_action_just_released("ui_right") || Input.is_action_just_released("ui_down") || Input.is_action_just_released("ui_left") || Input.is_action_just_released("ui_up")):
var seek_time = get_node(anim_player).get_animation(tree_root.get_node("StopAnim").animation).length - movement_script.pose_warping_instance.CalculateStopTime((movement_script.actual_velocity * Vector3(1.0,0.0,1.0)),movement_script.deacceleration * movement_script.input_direction)
set("parameters/Transition/StopSeek/seek_position",seek_time)
if !movement_script.input_is_moving:
set("parameters/Transition/transition_request","Stop")
#set("parameters/VelocityDirection/Standing/transition_request","Stop")
#Rotate In Place
if movement_script.is_rotating_in_place:
if movement_script.rotation_difference_camera_mesh > 0:
set("parameters/Transition/transition_request","AnimTurnLeft")
else:
set("parameters/Transition/transition_request","AnimTurnRight")
#set("parameters/Turn/blend_amount" , 1 if movement_script.is_rotating_in_place else 0)
#set("parameters/RightOrLeft/blend_amount" ,0 if movement_script.rotation_difference_camera_mesh > 0 else 1)

View file

@ -19,5 +19,5 @@ class_name GameAttribute
var can_use:bool = true
func set_attribute(prev_v, current_v):
func set_attribute(_prev_v, _current_v):
pass

View file

@ -4,14 +4,14 @@ class_name HealthAttribute
@export_category("Visual Bar")
@export var health_bar : ProgressBar
func set_attribute(prev_v, current_v):
func set_attribute(_prev_v, current_v):
if !attributes_manager:
return
if current_v <= 0.0: # and not dead
pass #death
func _process(delta):
func _process(_delta):
if health_bar:
health_bar.max_value = maximum_value
health_bar.value = current_value

View file

@ -8,5 +8,6 @@ var attributes : Dictionary
func _ready():
for child in get_children():
if !(child is GameAttribute):
assert("Only GameAttribute childs are allowed")
continue
#assert( !(child is GameAttribute), "Only GameAttribute childs are allowed")
attributes[child.attribute_name] = child

View file

@ -13,26 +13,26 @@ class_name CameraComponent
#####################################
var CameraHOffset := 0.0
@export var view_angle : Global.view_angle = Global.view_angle.right_shoulder:
@export var view_angle : Global.VIEW_ANGLE = Global.VIEW_ANGLE.right_shoulder:
get: return view_angle
set(Newview_angle):
# if view_mode == Global.view_mode.first_person:
# if view_mode == Global.VIEW_MODE.first_person:
# return
view_angle = Newview_angle
if Camera:
match Newview_angle:
Global.view_angle.right_shoulder:
Global.VIEW_ANGLE.right_shoulder:
CameraHOffset = 0.45
update_camera_offset()
Global.view_angle.left_shoulder:
Global.VIEW_ANGLE.left_shoulder:
CameraHOffset = -0.45
update_camera_offset()
Global.view_angle.head:
Global.VIEW_ANGLE.head:
CameraHOffset = 0.0
update_camera_offset()
@export var view_mode : Global.view_mode = Global.view_mode.third_person :
@export var view_mode : Global.VIEW_MODE = Global.VIEW_MODE.third_person :
get: return view_mode
set(Newview_mode):
view_mode = Newview_mode
@ -40,12 +40,12 @@ var CameraHOffset := 0.0
VObject.rotation.x = 0.0
if SpringArm:
match view_mode:
Global.view_mode.first_person:
view_angle = Global.view_angle.head
PlayerRef.rotation_mode = Global.rotation_mode.looking_direction
Global.VIEW_MODE.first_person:
view_angle = Global.VIEW_ANGLE.head
PlayerRef.rotation_mode = Global.ROTATION_MODE.looking_direction
SpringArm.spring_length = -0.4
VObject = Camera
Global.view_mode.third_person:
Global.VIEW_MODE.third_person:
SpringArm.spring_length = 1.75
VObject = SpringArm
@ -71,20 +71,20 @@ func _physics_process(delta):
if camera_settings.camera_change_fov_on_speed and PlayerRef.actual_velocity.length() > camera_settings.camera_fov_change_starting_speed:
smooth_fov(current_fov + clampf((PlayerRef.actual_velocity.length()-camera_settings.camera_fov_change_starting_speed)*(camera_settings.camera_max_fov_change/10.0),0,camera_settings.camera_max_fov_change))
SpringArm.position = SpringArm.position.lerp((get_parent().global_position + spring_arm_position_relative_to_player) if view_mode == Global.view_mode.third_person else first_person_camera_bone.global_position,(1/camera_settings.camera_inertia) if view_mode == Global.view_mode.third_person else 1.0)
SpringArm.position = SpringArm.position.lerp((get_parent().global_position + spring_arm_position_relative_to_player) if view_mode == Global.VIEW_MODE.third_person else first_person_camera_bone.global_position,(1/camera_settings.camera_inertia) if view_mode == Global.VIEW_MODE.third_person else 1.0)
camera_v = clamp(camera_v,deg_to_rad(camera_vertical_min),deg_to_rad(camera_vertical_max))
HObject.rotation.y = lerp(HObject.rotation.y,camera_h,delta * acceleration_h)
VObject.rotation.x = lerp(VObject.rotation.x,camera_v,delta * acceleration_v)
match PlayerRef.rotation_mode:
Global.rotation_mode.aiming:
if PlayerRef.gait == Global.gait.sprinting: # character can't sprint while aiming
PlayerRef.gait = Global.gait.running
Global.ROTATION_MODE.aiming:
if PlayerRef.gait == Global.GAIT.sprinting: # character can't sprint while aiming
PlayerRef.gait = Global.GAIT.running
smooth_fov(60.0)
Global.rotation_mode.velocity_direction:
Global.ROTATION_MODE.velocity_direction:
smooth_fov(90.0)
Global.rotation_mode.looking_direction:
Global.ROTATION_MODE.looking_direction:
smooth_fov(90.0)
@ -103,13 +103,13 @@ func smooth_fov(_current_fov:float):
tween.tween_callback(func(): changing_view=false)
func smooth_camera_transition(pos:Vector3, look_at:Vector3, duration:float = 1.0 ,ease:Tween.EaseType = Tween.EASE_IN_OUT, trans:Tween.TransitionType = Tween.TRANS_LINEAR):
func smooth_camera_transition(pos:Vector3, look_at:Vector3, duration:float = 1.0 ,ease_:Tween.EaseType = Tween.EASE_IN_OUT, trans:Tween.TransitionType = Tween.TRANS_LINEAR):
# Camera.global_position = Camera.to_global(Camera.global_position)
Camera.top_level = true
var tween := create_tween()
tween.set_parallel()
tween.tween_property(Camera,"position",pos,duration).set_ease(ease).set_trans(trans)
tween.tween_method(func(arr:Array): Camera.look_at_from_position(arr[0],arr[1]),[Camera.position,look_at],[pos,look_at],duration).set_ease(ease).set_trans(trans)
tween.tween_property(Camera,"position",pos,duration).set_ease(ease_).set_trans(trans)
tween.tween_method(func(arr:Array): Camera.look_at_from_position(arr[0],arr[1]),[Camera.position,look_at],[pos,look_at],duration).set_ease(ease_).set_trans(trans)
var reseting : bool = false
func reset_camera_transition(smooth_transition: bool = true):
@ -126,7 +126,6 @@ func reset_camera_transition(smooth_transition: bool = true):
tween.tween_property(Camera,"position",Vector3(0,0,SpringArm.spring_length),1.0)
tween.tween_property(Camera,"rotation",Vector3.ZERO,1.0)
tween.tween_callback(func(): reseting=false)
else:
Camera.rotation = Vector3.ZERO
Camera.top_level = false

View file

@ -155,26 +155,26 @@ var animation_is_moving_backward_relative_to_camera : bool
var animation_velocity : Vector3
#status
var movement_state = Global.movement_state.grounded
var movement_action = Global.movement_action.none
@export var movement_state = Global.MOVEMENT_STATE.grounded
var movement_action = Global.MOVEMENT_ACTION.none
@export_category("States")
@export var rotation_mode : Global.rotation_mode = Global.rotation_mode.velocity_direction :
@export var rotation_mode : Global.ROTATION_MODE = Global.ROTATION_MODE.velocity_direction :
get: return rotation_mode
set(Newrotation_mode):
rotation_mode = Newrotation_mode
update_character_movement()
@export var gait : Global.gait = Global.gait.walking :
@export var gait : Global.GAIT = Global.GAIT.walking : # Demarche (attente, marche, ...)
get: return gait
set(Newgait):
gait = Newgait
update_character_movement()
@export var stance : Global.stance = Global.stance.standing :
@export var stance : Global.STANCE = Global.STANCE.standing : # Position (debout, accroupi, ..)
set(Newstance):
stance = Newstance
update_character_movement()
@export var overlay_state = Global.overlay_state
@export var overlay_state = Global.OVERLAY_STATE
@export_category("Animations")
@export var TurnLeftAnim : String = "TurnLeft":
@ -193,11 +193,11 @@ var movement_action = Global.movement_action.none
set(value):
IdleAnim = value
update_animations()
@export var WalkForwardAnim : String = "Walk":
@export var WalkForwardAnim : String = "WalkForward":
set(value):
WalkForwardAnim = value
update_animations()
@export var WalkBackwardAnim : String = "WalkingBackward":
@export var WalkBackwardAnim : String = "WalkBackward":
set(value):
WalkBackwardAnim = value
update_animations()
@ -231,49 +231,49 @@ var movement_action = Global.movement_action.none
func update_animations():
if !anim_ref:
return
anim_ref.tree_root.get_node("AnimTurnLeft").animation = TurnLeftAnim
anim_ref.tree_root.get_node("AnimTurnRight").animation = TurnRightAnim
anim_ref.tree_root.get_node("FallAnimation").animation = FallingAnim
#var velocity_direction : AnimationNodeBlendTree = anim_ref.tree_root.get_node("VelocityDirection")
anim_ref.tree_root.get_node("Idle").animation = IdleAnim
anim_ref.tree_root.get_node("WalkForward").animation = WalkForwardAnim
anim_ref.tree_root.get_node("WalkBackward").animation = WalkBackwardAnim
anim_ref.tree_root.get_node("JogForward").animation = JogForwardAnim
anim_ref.tree_root.get_node("JogBackward").animation = JogBackwardAnim
anim_ref.tree_root.get_node("Run").animation = RunAnim
anim_ref.tree_root.get_node("StopAnim").animation = StopAnim
anim_ref.tree_root.get_node("CrouchIdle").animation = CrouchIdleAnim
anim_ref.tree_root.get_node("CrouchWalkingForward").animation = CrouchWalkAnim
anim_ref.get_tree_root().get_node("AnimTurnLeft").set_animation(TurnLeftAnim)
anim_ref.get_tree_root().get_node("AnimTurnRight").animation = TurnRightAnim
anim_ref.get_tree_root().get_node("FallAnimation").animation = FallingAnim
#var velocity_direction : AnimationNodeBlendTree = anim_ref.get_tree_root().get_node("VelocityDirection")
anim_ref.get_tree_root().get_node("Idle").animation = IdleAnim
anim_ref.get_tree_root().get_node("WalkForward").animation = WalkForwardAnim
anim_ref.get_tree_root().get_node("WalkBackward").animation = WalkBackwardAnim
anim_ref.get_tree_root().get_node("JogForward").animation = JogForwardAnim
anim_ref.get_tree_root().get_node("JogBackward").animation = JogBackwardAnim
anim_ref.get_tree_root().get_node("Run").animation = RunAnim
anim_ref.get_tree_root().get_node("StopAnim").animation = StopAnim
anim_ref.get_tree_root().get_node("CrouchIdle").animation = CrouchIdleAnim
anim_ref.get_tree_root().get_node("CrouchWalkingForward").animation = CrouchWalkAnim
func update_character_movement():
match rotation_mode:
Global.rotation_mode.velocity_direction:
Global.ROTATION_MODE.velocity_direction:
# if skeleton_ref:
# skeleton_ref.modification_stack.enabled = false
tilt = false
match stance:
Global.stance.standing:
Global.STANCE.standing:
current_movement_data = velocity_direction_standing_data
Global.stance.crouching:
Global.STANCE.crouching:
current_movement_data = velocity_direction_crouch_data
Global.rotation_mode.looking_direction:
Global.ROTATION_MODE.looking_direction:
# if skeleton_ref:
# skeleton_ref.modification_stack.enabled = false #Change to true when Godot fixes the bug.
tilt = true
match stance:
Global.stance.standing:
Global.STANCE.standing:
current_movement_data = looking_direction_standing_data
Global.stance.crouching:
Global.STANCE.crouching:
current_movement_data = looking_direction_crouch_data
Global.rotation_mode.aiming:
Global.ROTATION_MODE.aiming:
match stance:
Global.stance.standing:
Global.STANCE.standing:
current_movement_data = aim_standing_data
Global.stance.crouching:
Global.STANCE.crouching:
current_movement_data = aim_crouch_data
#####################################
@ -310,13 +310,13 @@ func _ready():
update_animations()
update_character_movement()
#var pose_warping_instance = pose_warping.new()
var pose_warping_instance = PoseWarping.new()
func _process(delta):
calc_animation_data()
var orientation_warping_condition = rotation_mode != Global.rotation_mode.velocity_direction and movement_state == Global.movement_state.grounded and movement_action == Global.movement_action.none and gait != Global.gait.sprinting and input_is_moving
#pose_warping_instance.orientation_warping( orientation_warping_condition,camera_root.HObject,animation_velocity,skeleton_ref,"Hips",["Spine","Spine1","Spine2"],0.0,delta)
var orientation_warping_condition = rotation_mode != Global.ROTATION_MODE.velocity_direction and movement_state == Global.MOVEMENT_STATE.grounded and movement_action == Global.MOVEMENT_ACTION.none and gait != Global.GAIT.sprinting and input_is_moving
pose_warping_instance.orientation_warping( orientation_warping_condition,camera_root.HObject,animation_velocity,skeleton_ref,"Hips",["Spine","Spine1","Spine2"],0.0,delta)
func _physics_process(delta):
#Debug()
@ -324,46 +324,46 @@ func _physics_process(delta):
aim_rate_h = abs((camera_root.HObject.rotation.y - previous_aim_rate_h) / delta)
previous_aim_rate_h = camera_root.HObject.rotation.y
#
# animation_stride_warping()
#animation_stride_warping()
match movement_state:
Global.movement_state.none:
Global.MOVEMENT_STATE.none:
pass
Global.movement_state.grounded:
Global.MOVEMENT_STATE.grounded:
#------------------ Rotate Character Mesh ------------------#
match movement_action:
Global.movement_action.none:
Global.MOVEMENT_ACTION.none:
match rotation_mode:
Global.rotation_mode.velocity_direction:
Global.ROTATION_MODE.velocity_direction:
if (is_moving and input_is_moving) or (actual_velocity * Vector3(1.0,0.0,1.0)).length() > 0.5:
smooth_character_rotation(actual_velocity,calc_grounded_rotation_rate(),delta)
Global.rotation_mode.looking_direction:
Global.ROTATION_MODE.looking_direction:
if (is_moving and input_is_moving) or (actual_velocity * Vector3(1.0,0.0,1.0)).length() > 0.5:
smooth_character_rotation(-camera_root.HObject.transform.basis.z if gait != Global.gait.sprinting else actual_velocity,calc_grounded_rotation_rate(),delta)
smooth_character_rotation(-camera_root.HObject.transform.basis.z if gait != Global.GAIT.sprinting else actual_velocity,calc_grounded_rotation_rate(),delta)
rotate_in_place_check()
Global.rotation_mode.aiming:
Global.ROTATION_MODE.aiming:
if (is_moving and input_is_moving) or (actual_velocity * Vector3(1.0,0.0,1.0)).length() > 0.5:
smooth_character_rotation(-camera_root.HObject.transform.basis.z,calc_grounded_rotation_rate(),delta)
rotate_in_place_check()
Global.movement_action.rolling:
Global.MOVEMENT_ACTION.rolling:
if input_is_moving == true:
smooth_character_rotation(input_acceleration ,2.0,delta)
Global.movement_state.in_air:
Global.MOVEMENT_STATE.in_air:
#------------------ Rotate Character Mesh In Air ------------------#
match rotation_mode:
Global.rotation_mode.velocity_direction:
Global.ROTATION_MODE.velocity_direction:
smooth_character_rotation(actual_velocity if (actual_velocity * Vector3(1.0,0.0,1.0)).length() > 1.0 else -camera_root.HObject.transform.basis.z,5.0,delta)
Global.rotation_mode.looking_direction:
Global.ROTATION_MODE.looking_direction:
smooth_character_rotation(actual_velocity if (actual_velocity * Vector3(1.0,0.0,1.0)).length() > 1.0 else -camera_root.HObject.transform.basis.z,5.0,delta)
Global.rotation_mode.aiming:
Global.ROTATION_MODE.aiming:
smooth_character_rotation(-camera_root.HObject.transform.basis.z ,15.0,delta)
#------------------ Mantle Check ------------------#
if input_is_moving == true:
mantle_check()
Global.movement_state.mantling:
Global.MOVEMENT_STATE.mantling:
pass
Global.movement_state.ragdoll:
Global.MOVEMENT_STATE.ragdoll:
pass
#------------------ Crouch ------------------#
@ -374,10 +374,10 @@ func _physics_process(delta):
character_node.velocity.y = lerp(character_node.velocity.y,vertical_velocity.y - character_node.get_floor_normal().y,delta * gravity)
character_node.move_and_slide()
if ground_check.is_colliding() and is_flying == false:
movement_state = Global.movement_state.grounded
movement_state = Global.MOVEMENT_STATE.grounded
else:
await get_tree().create_timer(0.1).timeout #wait a moment to see if the character lands fast (this means that the character didn't fall, but stepped down a bit.)
movement_state = Global.movement_state.in_air
movement_state = Global.MOVEMENT_STATE.in_air
if character_node is CharacterBody3D:
vertical_velocity += Vector3.DOWN * gravity * delta
if character_node is CharacterBody3D and character_node.is_on_ceiling():
@ -401,10 +401,10 @@ func crouch_update(delta):
ground_check.position.y = -(collision_shape_ref.shape.height/2)+collision_shape_ref.position.y + 0.2#Just a small margin
if stance == Global.stance.crouching:
if stance == Global.STANCE.crouching:
collision_shape_ref.shape.height -= crouch_switch_speed * delta /2
mesh_ref.transform.origin.y += crouch_switch_speed * delta /1.5
elif stance == Global.stance.standing and not head_bonked:
elif stance == Global.STANCE.standing and not head_bonked:
collision_shape_ref.shape.height += crouch_switch_speed * delta /2
mesh_ref.transform.origin.y -= crouch_switch_speed * delta /1.5
elif head_bonked:
@ -431,7 +431,7 @@ func stair_move():
var stair_top_collision = direct_state.intersect_ray(climb_ray_info)
if stair_top_collision:
if stair_top_collision.position.y - character_node.global_position.y > 0 and stair_top_collision.position.y - character_node.global_position.y < 0.15:
movement_state = Global.movement_state.grounded
movement_state = Global.MOVEMENT_STATE.grounded
is_moving_on_stair = true
character_node.position.y += stair_top_collision.position.y - character_node.global_position.y
character_node.global_position += Vector3(0, 0, 0.01).rotated(Vector3.UP,movement_direction)
@ -451,7 +451,7 @@ func smooth_character_rotation(Target:Vector3,nodelerpspeed,delta):
mesh_ref.rotation.y = lerp_angle(mesh_ref.rotation.y, atan2(Target.x,Target.z) , delta * nodelerpspeed)
func set_bone_x_rotation(skeleton,bone_name, x_rot,CharacterRootNode):
func set_bone_x_rotation(skeleton,bone_name, x_rot, _CharacterRootNode):
var bone = skeleton.find_bone(bone_name)
var bone_transform : Transform3D = skeleton.global_pose_to_local_pose(bone,skeleton.get_bone_global_pose_no_override(bone))
var rotate_amount = x_rot
@ -474,7 +474,7 @@ func animation_stride_warping(): #this is currently being worked on and tested,
var Feet : Array = ["RightFoot","LeftFoot"]
var Thighs : Array = ["RightUpLeg","LeftUpLeg"]
var hips_distance_to_ground
#var hips_distance_to_ground
var stride_scale : float = 1.0
for Foot in Feet:
#Get Bones
@ -483,7 +483,7 @@ func animation_stride_warping(): #this is currently being worked on and tested,
var thigh_bone = skeleton_ref.find_bone(Thighs[Feet.find(Foot)])
var thigh_transform = skeleton_ref.get_bone_global_pose_no_override(thigh_bone)
var thigh_angle = thigh_transform.basis.get_euler().x
#var thigh_angle = thigh_transform.basis.get_euler().x
#Calculate
var stride_direction : Vector3 = Vector3.FORWARD # important to use in orientation warping
@ -493,9 +493,9 @@ func animation_stride_warping(): #this is currently being worked on and tested,
return #Failed to get a plane origin/ we are probably in air
var scale_origin = Plane(stride_direction,stride_warping_plane_origin).project(bone_transform.origin)
var anim_speed = pow(hips_transform.origin.distance_to(bone_transform.origin),2) - pow(hips_transform.origin.y,2)
anim_speed = sqrt(abs(anim_speed))
stride_scale = clampf(distance_in_each_frame/anim_speed,0.0,2.0)
var anim_speed_ = pow(hips_transform.origin.distance_to(bone_transform.origin),2) - pow(hips_transform.origin.y,2)
anim_speed_ = sqrt(abs(anim_speed_))
stride_scale = clampf(distance_in_each_frame/anim_speed_,0.0,2.0)
# print(test_sphere.global_position)
var foot_warped_location : Vector3 = scale_origin + (bone_transform.origin - scale_origin) * stride_scale
@ -511,11 +511,11 @@ func calc_grounded_rotation_rate():
if input_is_moving == true:
match gait:
Global.gait.walking:
Global.GAIT.walking:
return lerp(current_movement_data.idle_rotation_rate,current_movement_data.walk_rotation_rate, Global.map_range_clamped((actual_velocity * Vector3(1.0,0.0,1.0)).length(),0.0,current_movement_data.walk_speed,0.0,1.0)) * clamp(aim_rate_h,1.0,3.0)
Global.gait.running:
Global.GAIT.running:
return lerp(current_movement_data.walk_rotation_rate,current_movement_data.run_rotation_rate, Global.map_range_clamped((actual_velocity * Vector3(1.0,0.0,1.0)).length(),current_movement_data.walk_speed,current_movement_data.run_speed,1.0,2.0)) * clamp(aim_rate_h,1.0,3.0)
Global.gait.sprinting:
Global.GAIT.sprinting:
return lerp(current_movement_data.run_rotation_rate,current_movement_data.sprint_rotation_rate, Global.map_range_clamped((actual_velocity * Vector3(1.0,0.0,1.0)).length(),current_movement_data.run_speed,current_movement_data.sprint_speed,2.0,3.0)) * clamp(aim_rate_h,1.0,2.5)
else:
return current_movement_data.idle_rotation_rate * clamp(aim_rate_h,1.0,3.0)
@ -546,7 +546,7 @@ var PrevVelocity :Vector3
## Adds input to move the character, should be called when Idle too, to execute deacceleration for CharacterBody3D or reset velocity for RigidBody3D.
## when Idle speed and direction should be passed as 0, and deacceleration passed, or leave them empty.
func add_movement_input(direction: Vector3 = Vector3.ZERO, Speed: float = 0, Acceleration: float = deacceleration if character_node is CharacterBody3D else 0) -> void:
func add_movement_input(direction: Vector3 = Vector3.ZERO, Speed: float = 0, Acceleration: float = deacceleration if character_node is CharacterBody3D else 0.0) -> void:
var max_speed : float = Speed
input_direction = direction

View file

@ -10,7 +10,7 @@ var team_id : int = 0
var last_attacker_id : int
@rpc("any_peer","reliable")
func damage(dmg:float,attacker_player_peer_id:int,impact_point:Vector3=Vector3.ZERO, impact_force:float=0.0, impact_bone_name:String=""):
func damage(dmg:float,attacker_player_peer_id:int,_impact_point:Vector3=Vector3.ZERO, _impact_force:float=0.0, _impact_bone_name:String=""):
last_attacker_id = attacker_player_peer_id
var health = attribute_map.attributes["health"].current_value

View file

@ -1,16 +1,26 @@
extends Node
#------------------ Player Enums ------------------#
enum gait {walking , running , sprinting}
enum movement_state {none , grounded , in_air , mantling, ragdoll}
enum movement_action {none ,low_mantle , high_mantle , rolling , getting_up}
enum overlay_state {default , rifle , pistol}
enum rotation_mode {velocity_direction , looking_direction , aiming}
enum stance {standing , crouching}
enum view_mode {third_person , first_person}
enum view_angle {right_shoulder , left_shoulder , head}
enum mantle_type {high_mantle , low_mantle, falling_catch}
enum movement_direction {forward , right, left, backward}
# Demarche (Attend, Marche, Cours, sprint
enum GAIT {waiting, walking , running , sprinting}
# Sol, Air, Couverture, poupee de chiffon
enum MOVEMENT_STATE {none , grounded , in_air , mantling, ragdoll}
#
enum MOVEMENT_ACTION {none ,low_mantle , high_mantle , rolling , getting_up}
# Fusis, Pistolet
enum OVERLAY_STATE {default , rifle , pistol}
#
enum ROTATION_MODE {velocity_direction , looking_direction , aiming}
# Position (debout, accroupi)
enum STANCE {standing , crouching}
#
enum VIEW_MODE {third_person , first_person}
#
enum VIEW_ANGLE {right_shoulder , left_shoulder , head}
# Type de cape/manteau
enum MANTLE_TYPE {high_mantle , low_mantle, falling_catch}
# Direction du mouvement (devant, droite, gauche, arriere)
enum MOVEMENT_DIRECTION {forward , right, left, backward}
func map_range_clamped(value,InputMin,InputMax,OutputMin,OutputMax):

View file

@ -1,70 +0,0 @@
extends Node
class_name LockSystem
#The array of locks that are presently applied. The player can perform an action if this array is empty.
#The locks can be used for any manner of things: player movement in cutscenes, restricting dialogue choices, door open conditions etc
var _locks = []
var lock_count : int :
get:
return _locks.size()
#An event to hook into - primarily for debugging.
signal Lock_Added(lockName:String)
signal Lock_Removed(lockName:String)
#This one should only emit if is_locked would have changed.
signal Lock_Status_Changed(newStatus:bool)
#A getter to see if any locks are being applied
@export var is_locked : bool :
get:
return _check_is_locked()
#If a lock called lock_name hasn't already been added, adds one.
func add_lock(lock_name:String):
#Don't add duplicate locks
if(contains_lock(lock_name)):
print_debug("Lock %lock is already added." % lock_name)
return
else:
#Add locks and emit events
_locks.append(lock_name)
emit_signal("Lock_Added", lock_name)
#if this is the first and only lock, the locked status has changed to true
if(_locks.size() == 1):
Lock_Status_Changed.emit(true)
return;
#Removes a lock with the name lock_name. Prints a message if it's not in there.
func remove_lock(lock_name:String):
if(contains_lock(lock_name)):
_locks.erase(lock_name)
#If there's now zero locks remaining, emit event
if(_locks.size() == 0):
Lock_Status_Changed.emit(false)
else:
print_debug("Lock %lock cannot be removed as it isn't there." % lock_name)
#Returns true if _locks has any entries added, false if no locks are being applied
func _check_is_locked():
return _locks.size() > 0;
#Returns true if a lock called lock_name is already added to _locks
func contains_lock(lock_name:String):
for lock in _locks:
if lock == lock_name:
return true;
return false;
#Prints all current locks - useful for tracking down issues when locks haven't been lifted
func debug_locks():
var log = "Printing all locks"
for lock in _locks:
print_debug("\n" + str(lock))
#To be used for debug - for when the locks need to be bypassed to test.
func debug_release_all_locks():
for lock in _locks:
Lock_Removed.emit(lock)
_locks.clear();

View file

@ -20,10 +20,6 @@ var h_rotation :float
var previous_rotation_mode
var direction := Vector3.ZERO
#####################################
#Locks System
@export var lock_system : LockSystem
#####################################
@export var mouse_sensitivity : float = 0.01
@ -41,13 +37,9 @@ func possess_character(p_character_component:CharacterMovementComponent,control:
character_component.camera_root.Camera.current = networking.is_local_authority()
func _physics_process(delta):
func _physics_process(_delta):
if !networking.is_local_authority():
return
if lock_system != null && lock_system.is_locked:
direction = Vector3.ZERO
character_component.add_movement_input()
return
#------------------ Input Movement ------------------#
h_rotation = character_component.camera_root.HObject.transform.basis.get_euler().y
@ -58,9 +50,9 @@ func _physics_process(delta):
remap(v_rotation,-PI/2,PI/2,-1.0,1.0) if character_component.is_flying == true else 0.0,
Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up"))
direction = direction.rotated(Vector3.UP,h_rotation).normalized()
if character_component.gait == Global.gait.sprinting :
if character_component.gait == Global.GAIT.sprinting :
character_component.add_movement_input(direction, character_component.current_movement_data.sprint_speed,character_component.current_movement_data.sprint_acceleration)
elif character_component.gait == Global.gait.running:
elif character_component.gait == Global.GAIT.running:
character_component.add_movement_input(direction, character_component.current_movement_data.run_speed,character_component.current_movement_data.run_acceleration)
else:
character_component.add_movement_input(direction, character_component.current_movement_data.walk_speed,character_component.current_movement_data.walk_acceleration)
@ -72,55 +64,55 @@ func _physics_process(delta):
#------------------ Input Crouch ------------------#
if UsingCrouchToggle == false:
if Input.is_action_pressed("ui_crouch"):
if character_component.stance != Global.stance.crouching:
character_component.stance = Global.stance.crouching
if character_component.stance != Global.STANCE.crouching:
character_component.stance = Global.STANCE.crouching
else:
if character_component.stance != Global.stance.standing:
character_component.stance = Global.stance.standing
if character_component.stance != Global.STANCE.standing:
character_component.stance = Global.STANCE.standing
else:
if Input.is_action_just_pressed("ui_crouch"):
character_component.stance = Global.stance.standing if character_component.stance == Global.stance.crouching else Global.stance.crouching
character_component.stance = Global.STANCE.standing if character_component.stance == Global.STANCE.crouching else Global.STANCE.crouching
#------------------ Sprint ------------------#
if UsingSprintToggle:
if Input.is_action_just_pressed("ui_sprint"):
if character_component.gait == Global.gait.walking:
character_component.gait = Global.gait.running
elif character_component.gait == Global.gait.running:
character_component.gait = Global.gait.sprinting
elif character_component.gait == Global.gait.sprinting:
character_component.gait = Global.gait.walking
if character_component.gait == Global.GAIT.walking:
character_component.gait = Global.GAIT.running
elif character_component.gait == Global.GAIT.running:
character_component.gait = Global.GAIT.sprinting
elif character_component.gait == Global.GAIT.sprinting:
character_component.gait = Global.GAIT.walking
else:
if Input.is_action_just_pressed("ui_sprint"):
if character_component.gait == Global.gait.walking:
character_component.gait = Global.gait.running
elif character_component.gait == Global.gait.running:
character_component.gait = Global.gait.sprinting
if character_component.gait == Global.GAIT.walking:
character_component.gait = Global.GAIT.running
elif character_component.gait == Global.GAIT.running:
character_component.gait = Global.GAIT.sprinting
if Input.is_action_just_released("ui_sprint"):
if character_component.gait == Global.gait.sprinting or character_component.gait == Global.gait.walking:
character_component.gait = Global.gait.walking
elif character_component.gait == Global.gait.running:
if character_component.gait == Global.GAIT.sprinting or character_component.gait == Global.GAIT.walking:
character_component.gait = Global.GAIT.walking
elif character_component.gait == Global.GAIT.running:
await get_tree().create_timer(0.4).timeout
if character_component.gait == Global.gait.running:
character_component.gait = Global.gait.walking
if character_component.gait == Global.GAIT.running:
character_component.gait = Global.GAIT.walking
#------------------ Input Aim ------------------#
if Input.is_action_pressed("ui_aim"):
if character_component.rotation_mode != Global.rotation_mode.aiming:
if character_component.rotation_mode != Global.ROTATION_MODE.aiming:
previous_rotation_mode = character_component.rotation_mode
character_component.rotation_mode = Global.rotation_mode.aiming
character_component.rotation_mode = Global.ROTATION_MODE.aiming
else:
if character_component.rotation_mode == Global.rotation_mode.aiming:
if character_component.rotation_mode == Global.ROTATION_MODE.aiming:
character_component.rotation_mode = previous_rotation_mode
#------------------ Jump ------------------#=
if OnePressJump == true:
if Input.is_action_just_pressed("ui_jump"):
if character_component.stance != Global.stance.standing:
character_component.stance = Global.stance.standing
if character_component.stance != Global.STANCE.standing:
character_component.stance = Global.STANCE.standing
else:
character_component.jump()
else:
if Input.is_action_pressed("ui_jump"):
if character_component.stance != Global.stance.standing:
character_component.stance = Global.stance.standing
if character_component.stance != Global.STANCE.standing:
character_component.stance = Global.STANCE.standing
else:
character_component.jump()
@ -153,7 +145,7 @@ func _input(event):
if Input.is_action_just_released("ui_switch_camera_view"):
if view_changed_recently == false:
view_changed_recently = true
character_component.camera_root.view_angle = character_component.camera_root.view_angle + 1 if character_component.camera_root.view_angle < 2 else 0
character_component.camera_root.view_angle = (character_component.camera_root.view_angle + 1) as Global.VIEW_ANGLE if character_component.camera_root.view_angle < 2 else 0 as Global.VIEW_ANGLE
await get_tree().create_timer(0.3).timeout
view_changed_recently = false
else:
@ -161,7 +153,7 @@ func _input(event):
if Input.is_action_just_pressed("ui_switch_camera_view"):
await get_tree().create_timer(0.2).timeout
if view_changed_recently == false:
character_component.camera_root.view_mode = character_component.camera_root.view_mode + 1 if character_component.camera_root.view_mode < 1 else 0
character_component.camera_root.view_mode = (character_component.camera_root.view_mode + 1) as Global.VIEW_MODE if character_component.camera_root.view_mode < 1 else 0 as Global.VIEW_MODE
view_changed_recently = true
if networking.is_local_authority():
if event.is_action_pressed("ui_enable_sdfgi"):
@ -175,13 +167,7 @@ func _input(event):
character_component.ragdoll = true
if character_component.rotation_mode == Global.rotation_mode.velocity_direction:
if character_component.rotation_mode == Global.ROTATION_MODE.velocity_direction:
if character_component.camera_root != null:
if character_component.camera_root.view_mode == Global.view_mode.first_person:
character_component.camera_root.view_mode = Global.view_mode.third_person
if(Input.is_action_pressed("ui_pause")):
if(lock_system.contains_lock("pauseGame")):
lock_system.remove_lock("pauseGame")
else:
lock_system.add_lock("pauseGame")
if character_component.camera_root.view_mode == Global.VIEW_MODE.first_person:
character_component.camera_root.view_mode = Global.VIEW_MODE.third_person

View file

@ -3,7 +3,7 @@ class_name PlayerGameplayComponent
@export_group("Stamina System", "stamina_")
@export var stamina_use: bool = false
@export var stamina_energy_consumption: float = 15.0#per second
@export var stamina_energy_consumption: float = 15.0 #per second
@export var stamina_attribute: GameAttribute
@export var networking : PlayerNetworkingComponent
@ -14,11 +14,11 @@ func _ready():
func _process(delta):
if gait != Global.gait.sprinting and stamina_use:
if gait != Global.GAIT.sprinting and stamina_use:
stamina_attribute.being_used = false
if gait == Global.gait.sprinting and stamina_use:
if gait == Global.GAIT.sprinting and stamina_use:
if !stamina_attribute.can_use or stamina_attribute.current_value < stamina_energy_consumption*delta:
gait = Global.gait.running
gait = Global.GAIT.running
return
stamina_attribute.being_used = true
stamina_attribute.current_value -= stamina_energy_consumption*delta
@ -28,9 +28,9 @@ func _physics_process(delta):
# Debug()
if !networking.is_local_authority():
if input_is_moving:
if gait == Global.gait.sprinting:
if gait == Global.GAIT.sprinting:
add_movement_input(input_direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
elif gait == Global.GAIT.running:
add_movement_input(input_direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(input_direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
@ -40,12 +40,12 @@ func _physics_process(delta):
return
#------------------ Look At ------------------#
match rotation_mode:
Global.rotation_mode.velocity_direction:
Global.ROTATION_MODE.velocity_direction:
if input_is_moving:
ik_look_at(actual_velocity + Vector3(0.0,1.0,0.0))
Global.rotation_mode.looking_direction:
Global.ROTATION_MODE.looking_direction:
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
Global.rotation_mode.aiming:
Global.ROTATION_MODE.aiming:
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
#func Debug():
# $Status/Label.text = "InputSpeed : %s" % input_velocity.length()

View file

@ -6,7 +6,7 @@ class_name PlayerNetworkingComponent
var sync_camera_h_transform : Transform3D
var sync_camera_v_transform : Transform3D
var sync_view_mode : Global.view_mode = Global.view_mode.third_person
var sync_view_mode : Global.VIEW_MODE = Global.VIEW_MODE.third_person
var sync_CameraHOffset : float
var sync_position : Vector3:
set(value):
@ -15,11 +15,11 @@ var sync_position : Vector3:
var sync_mesh_rotation : Vector3
var sync_direction : Vector3
var sync_input_is_moving : bool
var sync_gait : Global.gait = Global.gait.walking
var sync_rotation_mode : Global.rotation_mode = Global.rotation_mode.velocity_direction
var sync_stance : Global.stance = Global.stance.standing
var sync_movement_state : Global.movement_state = Global.movement_state.grounded
var sync_movement_action : Global.movement_action = Global.movement_action.none
var sync_gait : Global.GAIT = Global.GAIT.walking
var sync_rotation_mode : Global.ROTATION_MODE = Global.ROTATION_MODE.velocity_direction
var sync_stance : Global.STANCE = Global.STANCE.standing
var sync_movement_state : Global.MOVEMENT_STATE = Global.MOVEMENT_STATE.grounded
var sync_movement_action : Global.MOVEMENT_ACTION = Global.MOVEMENT_ACTION.none
var sync_velocity : Vector3
var processed_position : bool
@ -36,7 +36,7 @@ func _ready():
pass
func set_id(value:int):
func set_id(value:int) -> void:
id = value

View file

@ -0,0 +1,66 @@
extends Node
class_name PoseWarping
## For Predicting Stop Location
## it uses a linear equation : d = v*t + 0.5 * a * t^2
## v is velocity. t is time. a is acceleration
func CalculateStopLocation(CurrentCharacterLocation:Vector3,Velocity:Vector3,deacceleration:Vector3,_delta):
var time = CalculateStopTime(Velocity,deacceleration)
return CurrentCharacterLocation + (Velocity * time + 0.5*deacceleration*pow(time,2))
func CalculateStopTime(Velocity:Vector3,deacceleration:Vector3):
var time = Velocity.length() / deacceleration.length()
return time
var previous_direction : float
var orientation_direction : float
var cleared_override : bool = true
func orientation_warping(enabled:bool,CameraObject, Velocity:Vector3, skeleton_ref:Skeleton3D, Hip :String= "Hips", Spines :Array[String]= ["Spine","Spine1","Spine2"], Offset := 0.0, delta :float= 1.0, turn_rate :float= 10.0):
if !enabled and !cleared_override:
set_bone_y_rotation(skeleton_ref,Hip,0,false)
for bone in Spines:
set_bone_y_rotation(skeleton_ref,bone,0,false)
cleared_override = true
if is_equal_approx(Velocity.length(),0.0) or !enabled:
return
cleared_override = false
var CameraAngle :Quaternion = Quaternion(Vector3(0,1,0),atan2(-CameraObject.transform.basis.z.z, -CameraObject.transform.basis.z.x))
var VelocityAngle :Quaternion = Quaternion(Vector3(0,1,0),atan2(Velocity.z, Velocity.x))
var IsMovingBackwardRelativeToCamera :bool = false if -Velocity.rotated(Vector3.UP,-CameraObject.transform.basis.get_euler().y).z >= -0.1 else true
var IsMovingLeftRelativeToCamera :bool = false if -Velocity.rotated(Vector3.UP,-CameraObject.transform.basis.get_euler().y).x >= -0.1 else true
var rotation_difference_camera_velocity :float = CameraAngle.angle_to(VelocityAngle)
previous_direction = orientation_direction
orientation_direction = rotation_difference_camera_velocity
if IsMovingBackwardRelativeToCamera:
# Make the legs face forward just like the forward walking
orientation_direction *= -1
orientation_direction = orientation_direction + PI
# Set Left or Right
if IsMovingLeftRelativeToCamera:
orientation_direction *= -1
if IsMovingBackwardRelativeToCamera:
# since we rotated the legs to face forward, then the right and left will be reversed
# so we need to reverse it back again after getting the right and left values
orientation_direction *= -1
orientation_direction = clampf(lerp_angle(previous_direction,orientation_direction,delta*turn_rate),-PI/2, PI/2)
#Orient bones to face the forward direction
set_bone_y_rotation(skeleton_ref,Hip,orientation_direction)
for bone in Spines:
set_bone_y_rotation(skeleton_ref,bone,(-orientation_direction/(Spines.size()))+Offset)
func set_bone_y_rotation(skeleton:Skeleton3D,bone_name:String, y_rot:float, presistant:bool=true):
var bone = skeleton.find_bone(bone_name)
var bone_transform : Transform3D = skeleton.get_bone_global_pose_no_override(bone)
bone_transform = bone_transform.rotated(Vector3(0,1,0), y_rot)
skeleton.set_bone_global_pose_override(bone, bone_transform,1.0,presistant)

View file

@ -24,7 +24,7 @@ signal detected(object: Node3D) #this activates for all
func _ready():
detection_raycast.add_exception(get_parent())
func _process(delta):
func _process(_delta):
if detection_raycast.is_colliding():
if detected_player == detection_raycast.get_collider() or detected_object == detection_raycast.get_collider():
return

View file

@ -27,11 +27,51 @@ func set_otherplayer(value:bool):
func _ready():
$SpringArm3D/Camera3D.set_current(false)
#$PlayerGameplayComponent.update_animations()
func set_current_camera():
func set_current_camera() -> void:
$SpringArm3D/Camera3D.set_current(true)
func set_id(value:int):
func set_id(value:int) -> void:
$PlayerNetworkingComponent.set_id(value)
func set_activate() -> void:
#$AnimationTree.set_active(true)
#$AnimationTree.set("parameters/Transition/transition_request","Idle")
pass
#func set_animation_tree_blend_positions(input_vector: Vector2) -> void:
# #print("Blend Position: ", input_vector)
# $AnimationTree.set("parameters/Idle/blend_position", input_vector)
# $AnimationTree.set("parameters/Walk/blend_position", input_vector)
func get_animation() -> String:
return $AnimationTree.get("parameters/Transition/current_state") + \
", " + str($AnimationTree.get("parameters/InAir/blend_amount")) + \
", active:" + str($AnimationTree.is_active()) + \
", " + str($AnimationPlayer.get_current_animation()) + \
", " + str($AnimationPlayer.get_current_animation_position()) + \
", " + str($AnimationPlayer.get_autoplay()) + \
", playing:" + str($AnimationPlayer.is_playing()) + \
", " + str($AnimationTree.get("parameters/Transition/current_state")) + \
", " + str($AnimationTree.get("parameters/Transition/current_index"))
func get_gait() -> String:
return Global.GAIT.keys()[$CharacterMovementComponent.gait]
func get_stance() -> String:
return Global.STANCE.keys()[$CharacterMovementComponent.stance]
func get_rotation_mode() -> String:
return Global.ROTATION_MODE.keys()[$CharacterMovementComponent.rotation_mode]
func get_movement_state() -> String:
return Global.MOVEMENT_STATE.keys()[$CharacterMovementComponent.movement_state]

File diff suppressed because one or more lines are too long

View file

@ -20,6 +20,10 @@ config/icon="res://icon.svg"
Multi="*res://scenes/multi.gd"
Global="*res://player/Global.gd"
[display]
window/subwindows/embed_subwindows=false
[input]
ui_left={
@ -69,7 +73,8 @@ ui_sprint={
}
ui_jump={
"deadzone": 0.5,
"events": []
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null)
]
}
ui_interaction={
"deadzone": 0.5,
@ -81,7 +86,8 @@ ui_crouch={
}
ui_switch_camera_view={
"deadzone": 0.5,
"events": []
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":86,"physical_keycode":0,"key_label":0,"unicode":118,"echo":false,"script":null)
]
}
ui_ragdoll={
"deadzone": 0.5,
@ -104,6 +110,11 @@ ui_quit={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
ui_debug={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194343,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
[rendering]

View file

@ -1,11 +1,39 @@
extends Window
@export var node_players : Node = null:
set(value):
node_players = value
@export var node_me : Node = null:
set(value):
node_me = value
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _process(_delta):
if node_players:
$TabContainer/Perso/VBoxContainer/HBoxContainer/Count.set_text(str(node_players.get_child_count()))
$TabContainer/Perso/VBoxContainer/HBoxContainer2/Id.set_text(str(Multi.get_id()))
if node_players.get_child_count() > 0:
$TabContainer/Network/VBoxContainer/players/player0.set_text(str(node_players.get_child(0).get_global_position()))
print(str(node_players.get_child(0).get_global_position()))
if node_me:
$TabContainer/Network/VBoxContainer/me/me.set_text(str(node_me.get_child(0).get_global_position()))
var tmp:String = ""
tmp += "Anim: " + str(node_me.get_child(0).get_animation())
tmp += "\nGait: " + node_me.get_child(0).get_gait()
tmp += "\nStance: " + node_me.get_child(0).get_stance()
tmp += "\nRotation: " + node_me.get_child(0).get_rotation_mode()
tmp += "\nMovement: " + node_me.get_child(0).get_movement_state()
$TabContainer/Network/VBoxContainer/state/state.set_text(tmp)
func _on_close_requested():
hide()

View file

@ -17,6 +17,7 @@ grow_horizontal = 2
grow_vertical = 2
[node name="Perso" type="TabBar" parent="TabContainer"]
visible = false
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Perso"]
@ -38,7 +39,7 @@ text = "Count"
[node name="Count" type="Label" parent="TabContainer/Perso/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "0"
text = "-"
[node name="HBoxContainer2" type="HBoxContainer" parent="TabContainer/Perso/VBoxContainer"]
layout_mode = 2
@ -54,7 +55,6 @@ size_flags_horizontal = 3
text = "0"
[node name="Network" type="TabBar" parent="TabContainer"]
visible = false
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Network"]
@ -64,3 +64,43 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="players" type="HBoxContainer" parent="TabContainer/Network/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="TabContainer/Network/VBoxContainer/players"]
layout_mode = 2
text = "2nd player:"
[node name="player0" type="Label" parent="TabContainer/Network/VBoxContainer/players"]
layout_mode = 2
size_flags_vertical = 1
[node name="me" type="HBoxContainer" parent="TabContainer/Network/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="TabContainer/Network/VBoxContainer/me"]
layout_mode = 2
text = "me:"
[node name="me" type="Label" parent="TabContainer/Network/VBoxContainer/me"]
layout_mode = 2
size_flags_vertical = 1
text = "me"
[node name="state" type="HBoxContainer" parent="TabContainer/Network/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="TabContainer/Network/VBoxContainer/state"]
layout_mode = 2
text = "state:"
[node name="state" type="Label" parent="TabContainer/Network/VBoxContainer/state"]
layout_mode = 2
text = "anim"
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Network/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[connection signal="close_requested" from="." to="." method="_on_close_requested"]

View file

@ -50,12 +50,12 @@ func _on_focus_exited():
func _on_mouse_entered():
focus_ok = true
self.get_parent().CharacterBody3D.disabled = true
#self.get_parent().CharacterBody3D.disabled = true
func _on_mouse_exited():
focus_ok = false
self.get_parent().CharacterBody3D.disabled = false
#self.get_parent().CharacterBody3D.disabled = false
func open_windows():
focus_ok = false

View file

@ -16,9 +16,9 @@ var player_name: String
#const PLAYER = preload("res://player/character.tscn")
const player_path:String = "res://player/character.tscn"
@export var PlayerCharacter = preload(player_path)
#@export var debug_window: PackedScene
@export var debug_window: PackedScene
@onready var _MainWindow: Window = get_window()
#@onready var _MainWindow: Window = get_window()
func _ready():
_on_connexion_updated(Multi.Connexion.NONE)
@ -29,13 +29,13 @@ func _ready():
$PlayerSpawnLocation.add_child(p)
$PlayerSpawnLocation.set_visible(false)
p.set_otherplayer(false)
#Multi.set_player_position($PlayerSpawnLocation.get_child(0))
Multi.set_player_position($PlayerSpawnLocation.get_child(0))
Multi.connexion_updated.connect(_on_connexion_updated)
Multi.update_my_position.connect(_on_update_me)
Multi.update_player_position.connect(_on_update_player)
Multi.remove_player.connect(_on_remove_player)
#_MainWindow.gui_embed_subwindows = false # Make subwindows actual system windows <- VERY IMPORTANT
#$Window.world_2d = _MainWindow.world_2d
func create_view_window():
pass
@ -71,10 +71,11 @@ func _on_connexion_updated(new_state:Multi.Connexion):
$Panel.show()
elif new_state == Multi.Connexion.CONNECTED:
$Panel.hide()
$PlayerSpawnLocation.set_visible(true)
$PlayerSpawnLocation.get_child(0).set_current_camera()
$PlayerSpawnLocation.get_child(0).set_name(str(Multi.get_id()))
$PlayerSpawnLocation.get_child(0).set_id(Multi.get_id())
$PlayerSpawnLocation.get_child(0).set_activate()
$PlayerSpawnLocation.set_visible(true)
$CameraStarting.set_current(false)
else:
$CameraStarting.set_current(true)
@ -107,6 +108,8 @@ func _on_update_player(id:int, pos:Vector3):
child2.set_global_position(pos)
else:
print("Update player : ", id, " ", pos)
print(pos)
#pos.y += 10.0
child.set_global_position(pos)
#child.set_visible(true)
@ -136,16 +139,21 @@ func _on_remove_player(id:int):
# print("==========================")
func _process(delta):
# if $PlayerSpawnLocation:
# print(">", $PlayerSpawnLocation.get_global_position())
pass
#func _process(delta):
## if $PlayerSpawnLocation:
## print(">", $PlayerSpawnLocation.get_global_position())
# pass
func _input(event):
if event is InputEventKey:
if event.is_action_pressed("ui_quit"):
get_tree().quit()
elif event.is_action_pressed("ui_debug"):
var new_window: Window = debug_window.instantiate()
add_child(new_window)
new_window.node_players = $Players
new_window.node_me = $PlayerSpawnLocation
func set_player_position(pos: Vector3):

View file

@ -1,11 +1,13 @@
[gd_scene load_steps=10 format=3 uid="uid://bemavktwweaog"]
[gd_scene load_steps=11 format=3 uid="uid://bemavktwweaog"]
[ext_resource type="Shader" path="res://scenes/main.gdshader" id="1_caff6"]
[ext_resource type="Script" path="res://scenes/main.gd" id="1_ts8of"]
[ext_resource type="PackedScene" uid="uid://ddymq82ef22l2" path="res://scenes/DebugWindow.tscn" id="2_6hoce"]
[ext_resource type="Script" path="res://scenes/Window.gd" id="3_uwnj8"]
[sub_resource type="BoxShape3D" id="BoxShape3D_5dcgs"]
size = Vector3(1000, 1, 1000)
margin = 1.0
size = Vector3(1000, 0, 1000)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_gypq5"]
render_priority = 0
@ -13,7 +15,7 @@ shader = ExtResource("1_caff6")
[sub_resource type="BoxMesh" id="BoxMesh_fm2j6"]
material = SubResource("ShaderMaterial_gypq5")
size = Vector3(1000, 1, 1000)
size = Vector3(1000, 0, 1000)
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_0qg6h"]
@ -29,9 +31,9 @@ reflected_light_source = 2
[node name="main" type="Node3D"]
script = ExtResource("1_ts8of")
debug_window = ExtResource("2_6hoce")
[node name="ground" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="ground"]
shape = SubResource("BoxShape3D_5dcgs")
@ -53,6 +55,7 @@ environment = SubResource("Environment_12j7q")
title = "Connexion"
initial_position = 1
size = Vector2i(300, 200)
always_on_top = true
script = ExtResource("3_uwnj8")
[node name="VBoxContainer" type="VBoxContainer" parent="Window"]

View file

@ -183,7 +183,7 @@ func get_player_position():
if state_connexion != Connexion.CONNECTED:
return
var pos:PackedFloat64Array = PackedFloat64Array()
var posRaw:Vector3 = player_position.get_position()
var posRaw:Vector3 = player_position.get_global_position() #get_position()
pos.append(posRaw.x)
pos.append(posRaw.y)
pos.append(posRaw.z)

View file

@ -7,7 +7,7 @@ declare FORCE=0
declare IMPORT=0
declare ERASEIMPORT=0
declare WORKDIR="$(dirname $(readlink -f $0))"
declare GODOT_SRC="https://downloads.tuxfamily.org/godotengine/4.1.2/Godot_v4.1.2-stable_linux.x86_64.zip"
declare GODOT_SRC="https://downloads.tuxfamily.org/godotengine/4.1.3/Godot_v4.1.3-stable_linux.x86_64.zip"
declare OUTZIP="$WORKDIR/$(basename $GODOT_SRC)"
declare CLIENTDIR="$WORKDIR/client"
declare OPTION=""