bazar_alea/client/player/character.gd

168 lines
4.6 KiB
GDScript3
Raw Normal View History

2023-11-14 21:41:08 +00:00
extends CharacterBody3D
@export var speed = 5.0
@export var jump_velocity = 4.5
var camrot_h:float = 0.0
var camrot_v:float = 0.0
@export var h_acceleration:float = 10.0
@export var v_acceleration:float = 10.0
@export var h_sensitivity:float = 0.5
@export var v_sensitivity:float = 0.5
2023-11-24 23:00:05 +00:00
var save_rot:Vector3
2023-11-26 12:06:37 +00:00
var tick:int = 0
2023-11-30 21:06:23 +00:00
var jump:Vector3 = Vector3(0.0, 0.0, 0.0)
var tickjump: int = 0
2023-11-24 23:00:05 +00:00
2023-11-14 21:41:08 +00:00
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var otherplayer:bool = true:
get:
return otherplayer
set(value):
otherplayer = value
func set_otherplayer(value:bool):
otherplayer = value
2023-11-24 23:00:05 +00:00
#
#func _set(property:String, value) -> bool:
# if property == "position":
# print("changed position ",value)
# return false
2023-11-14 21:41:08 +00:00
func _ready():
$SpringArm3D/Camera3D.set_current(false)
2023-11-24 23:00:05 +00:00
set_process(false)
2023-11-30 21:06:23 +00:00
$CharacterMovementComponent.start_jump.connect(_on_start_jump)
2023-11-24 23:00:05 +00:00
# $CameraComponent.set_process(false)
# $PlayerController.set_process(false)
# $PlayerNetworkingComponent.set_process(false)
# $CharacterMovementComponent.set_process(false)
# $TargetingComponent.set_process(false)
# $CombatSystem.set_process(false)
# $AttributesManager.set_process(false)
# $AttributesManager/HealthAttribute.set_process(false)
# $AttributesManager/StaminaAttribute.set_process(false)
2023-11-20 22:18:02 +00:00
#$PlayerGameplayComponent.update_animations()
2023-11-14 21:41:08 +00:00
2023-11-30 21:06:23 +00:00
func _on_start_jump(vertical_velocity:Vector3):
jump = vertical_velocity
tickjump += 1
2023-11-22 23:05:33 +00:00
func get_my_position() -> Vector3:
#return $SpringArm3D/Camera3D.get_global_position()
return self.get_global_position()
func get_my_rotation() -> Vector3:
#return $SpringArm3D/Camera3D.get_global_rotation()
#return $Armature/Skeleton3D.get_global_rotation()
#print($Armature/Skeleton3D.get_global_rotation(), "---", $Armature.get_global_rotation())
return $Armature.get_global_rotation()
2023-11-30 21:06:23 +00:00
func is_jump() -> bool:
return jump != Vector3( 0.0, 0.0, 0.0)
func get_jump() -> Vector3:
var ret:Vector3 = jump
jump = Vector3(0.0, 0.0, 0.0)
return ret
func get_tickjump() -> int:
return tickjump
2023-11-26 12:06:37 +00:00
func update_player(ctick:int, pos:Vector3, rot:Vector3):
#print(tick, " - ", ctick)
if tick != ctick:
set_my_position(pos)
set_my_rotation(rot)
tick = ctick
2023-11-22 23:05:33 +00:00
func set_my_position(pos:Vector3):
self.set_global_position(pos)
func set_my_rotation(rot:Vector3):
2023-11-24 23:00:05 +00:00
save_rot = rot
print("Update ->" + str(rot))
$Armature.set_global_rotation(rot)
#$CharacterMovementComponent.input_direction = rot
2023-11-22 23:05:33 +00:00
pass
2023-11-20 22:18:02 +00:00
func set_current_camera() -> void:
2023-11-14 21:41:08 +00:00
$SpringArm3D/Camera3D.set_current(true)
2023-11-20 22:18:02 +00:00
func set_id(value:int) -> void:
2023-11-14 21:41:08 +00:00
$PlayerNetworkingComponent.set_id(value)
2023-11-19 19:41:38 +00:00
2023-11-20 22:18:02 +00:00
func set_activate() -> void:
#$AnimationTree.set_active(true)
#$AnimationTree.set("parameters/Transition/transition_request","Idle")
2023-11-24 23:00:05 +00:00
set_process(true)
2023-11-20 22:18:02 +00:00
#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)
2023-11-24 23:00:05 +00:00
func get_comment() -> String:
return str(save_rot) + \
" -> " + str($PlayerNetworkingComponent.is_local_authority()) + \
" -> " + str($CharacterMovementComponent.input_direction)
2023-11-19 19:41:38 +00:00
func get_animation() -> String:
return $AnimationTree.get("parameters/Transition/current_state") + \
2023-11-24 23:00:05 +00:00
", " + str($AnimationTree.get("parameters/InAir/blend_amount"))
# 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"))
2023-11-19 19:41:38 +00:00
func get_gait() -> String:
2023-11-20 22:18:02 +00:00
return Global.GAIT.keys()[$CharacterMovementComponent.gait]
2023-11-19 19:41:38 +00:00
func get_stance() -> String:
2023-11-20 22:18:02 +00:00
return Global.STANCE.keys()[$CharacterMovementComponent.stance]
2023-11-19 19:41:38 +00:00
func get_rotation_mode() -> String:
2023-11-20 22:18:02 +00:00
return Global.ROTATION_MODE.keys()[$CharacterMovementComponent.rotation_mode]
2023-11-19 19:41:38 +00:00
func get_movement_state() -> String:
2023-11-20 22:18:02 +00:00
return Global.MOVEMENT_STATE.keys()[$CharacterMovementComponent.movement_state]
2023-11-24 23:00:05 +00:00
#
func _process(_delta):
if ! $PlayerNetworkingComponent.is_local_authority():
if get_my_rotation() != save_rot:
print("Ohhhhhh : " + str( get_my_rotation()) + " != " + str(save_rot))
print("Ohhhhhh")
else:
print("Superrrr")
# $Armature.set_global_rotation(save_rot)