update mouvement player & camera with mousse

This commit is contained in:
AleaJactaEst 2023-05-04 00:00:19 +02:00
parent a94095128e
commit 3e7d670455
5 changed files with 54 additions and 6 deletions

View file

@ -344,6 +344,7 @@ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 1.1
light_energy = 10.0
[node name="Status" type="Control" parent="." index="11"]
visible = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0

View file

@ -71,8 +71,9 @@ func _input(event):
if Common.is_menu_visible():
return
if event is InputEventMouseMotion:
camera_h += -event.relative.x * mouse_sensitvity
camera_v += -event.relative.y * mouse_sensitvity
if Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_ONLY_MOUSE") or Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"):
camera_h += -event.relative.x * mouse_sensitvity
camera_v += -event.relative.y * mouse_sensitvity
func _physics_process(delta):

View file

@ -49,7 +49,10 @@ var crouch_height := 1.0
@export var crouch_switch_speed := 5.0
@export var rotation_in_place_min_angle := 90.0
#@export var rotation_in_place_min_angle := 90.0
@export var rotation_in_place_min_angle := 180.0
@export var rotation_in_place_back_min_angle := 5.0
@export var rotation_back_speed := 5.0
#Movement Values Settings
#you could play with the values to achieve different movement settings
@ -596,6 +599,23 @@ func rotate_in_place_check():
smooth_character_rotation(-camera_root.HObject.transform.basis.z,calc_grounded_rotation_rate(),get_physics_process_delta_time())
func rotate_in_place() -> bool:
# Function used to automatically turn perso (when we ask to reconcilaite camera)
var CameraAngle = Quaternion(Vector3(0,1,0),camera_root.HObject.rotation.y)
var MeshAngle = Quaternion(Vector3(0,1,0),mesh_ref.rotation.y)
rotation_difference_camera_mesh = rad_to_deg(MeshAngle.angle_to(CameraAngle) - PI)
if (CameraAngle.dot(MeshAngle)) > 0:
rotation_difference_camera_mesh *= -1
if floor(abs(rotation_difference_camera_mesh)) > rotation_in_place_back_min_angle:
is_rotating_in_place = true
smooth_character_rotation(-camera_root.HObject.transform.basis.z,rotation_back_speed,get_physics_process_delta_time())
return true
else:
is_rotating_in_place = false
return false
func ik_look_at(position: Vector3):
var lookatobject = character_node.get_node("LookAtObject")
if lookatobject:

View file

@ -8,7 +8,11 @@ extends CharacterMovementComponent
@export var UsingSprintToggle := false
@export var UsingCrouchToggle := false
#####################################
@export var mouse_sensitvity : float = 0.01
var player_h : float = 0
var player_v : float = 0
var reconciliate_rotate_player_back:bool = false
var h_rotation :float
#var v_rotation :float
@ -39,7 +43,18 @@ func _physics_process(delta):
if Common.is_menu_visible():
add_movement_input(direction,0,deacceleration)
return
if Input.is_action_pressed("INPUT_ACTION_FORWARD") || Input.is_action_pressed("INPUT_ACTION_BACK") || Input.is_action_pressed("INPUT_ACTION_RIGHT") || Input.is_action_pressed("INPUT_ACTION_LEFT") :
if Input.is_action_pressed("INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE") && Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"):
direction = Vector3(0.0,
0.0 if is_flying == true else 0.0,
-1.0)
direction = direction.rotated(Vector3.UP,h_rotation).normalized()
if gait == Global.gait.sprinting :
add_movement_input(direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
elif Input.is_action_pressed("INPUT_ACTION_FORWARD") || Input.is_action_pressed("INPUT_ACTION_BACK") || Input.is_action_pressed("INPUT_ACTION_RIGHT") || Input.is_action_pressed("INPUT_ACTION_LEFT") :
direction = Vector3(Input.get_action_strength("INPUT_ACTION_RIGHT") - Input.get_action_strength("INPUT_ACTION_LEFT"),
0.0 if is_flying == true else 0.0,
Input.get_action_strength("INPUT_ACTION_BACK") - Input.get_action_strength("INPUT_ACTION_FORWARD"))
@ -50,6 +65,8 @@ func _physics_process(delta):
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
elif reconciliate_rotate_player_back:
reconciliate_rotate_player_back = rotate_in_place()
else:
add_movement_input(direction,0,deacceleration)
@ -128,6 +145,15 @@ var view_changed_recently = false
func _input(event):
if Common.is_menu_visible():
return
#if event is InputEventMouseMotion:
if Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"):
reconciliate_rotate_player_back = true
# player_h += -event.relative.x * mouse_sensitvity
# player_v += -event.relative.y * mouse_sensitvity
# Common.msg_debug("player_h:" + str(player_h))
# if reconciliate_rotate_player_back:
# Common.msg_debug("h_rotation:" + str(h_rotation))
# pass
#------------------ Motion Warping test------------------#
if event.is_action_pressed("INPUT_ACTION_FIRE"):
anim_ref.active = false

File diff suppressed because one or more lines are too long