spacing in player

This commit is contained in:
Chris Bell 2024-12-15 14:31:04 -06:00
parent db0ea23ea8
commit 428c0a1f52

View File

@ -45,6 +45,7 @@ func _enter_tree() -> void:
camera.current = true camera.current = true
capture_mouse() capture_mouse()
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if !is_network_authority: return if !is_network_authority: return
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
@ -57,6 +58,7 @@ func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("jump") and !is_piloting: if Input.is_action_just_pressed("jump") and !is_piloting:
jumping = true jumping = true
func _input(event): func _input(event):
if !is_network_authority: return if !is_network_authority: return
if event.is_action_pressed("esc") and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: if event.is_action_pressed("esc") and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
@ -64,6 +66,7 @@ func _input(event):
elif event.is_action_pressed("esc") and not Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: elif event.is_action_pressed("esc") and not Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
capture_mouse() capture_mouse()
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if !is_network_authority: return if !is_network_authority: return
if current_ship != null: if current_ship != null:
@ -82,6 +85,7 @@ func _physics_process(delta: float) -> void:
_handle_joypad_camera_rotation(delta) _handle_joypad_camera_rotation(delta)
move_and_slide() move_and_slide()
func _process(delta: float) -> void: func _process(delta: float) -> void:
if !is_network_authority: return if !is_network_authority: return
@ -93,14 +97,17 @@ func _process(delta: float) -> void:
NetworkManager.sync_property(network_uuid, "global_rotation", global_rotation) NetworkManager.sync_property(network_uuid, "global_rotation", global_rotation)
previous_global_rotation = global_rotation previous_global_rotation = global_rotation
func capture_mouse() -> void: func capture_mouse() -> void:
if !is_network_authority: return if !is_network_authority: return
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func release_mouse() -> void: func release_mouse() -> void:
if !is_network_authority: return if !is_network_authority: return
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _rotate_camera(sens_mod: float = 1.0) -> void: func _rotate_camera(sens_mod: float = 1.0) -> void:
if !is_network_authority: return if !is_network_authority: return
var camera_sens_final = camera_sens var camera_sens_final = camera_sens
@ -110,6 +117,7 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
camera.rotation.y -= look_dir.x * camera_sens_final * sens_mod camera.rotation.y -= look_dir.x * camera_sens_final * sens_mod
camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens_final * sens_mod, -1.5, 1.5) camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens_final * sens_mod, -1.5, 1.5)
func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void: func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void:
var joypad_dir: Vector2 = Input.get_vector("look_left","look_right","look_up","look_down") var joypad_dir: Vector2 = Input.get_vector("look_left","look_right","look_up","look_down")
if joypad_dir.length() > 0: if joypad_dir.length() > 0:
@ -117,6 +125,7 @@ func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void
_rotate_camera(sens_mod) _rotate_camera(sens_mod)
look_dir = Vector2.ZERO look_dir = Vector2.ZERO
func walk(delta: float) -> Vector3: func walk(delta: float) -> Vector3:
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
move_dir = Input.get_vector("move_left", "move_right", "move_forwards", "move_backwards") move_dir = Input.get_vector("move_left", "move_right", "move_forwards", "move_backwards")
@ -125,10 +134,12 @@ func walk(delta: float) -> Vector3:
walk_vel = walk_vel.move_toward(walk_dir * speed * move_dir.length(), acceleration * delta) walk_vel = walk_vel.move_toward(walk_dir * speed * move_dir.length(), acceleration * delta)
return walk_vel return walk_vel
func _gravity(delta: float) -> Vector3: func _gravity(delta: float) -> Vector3:
grav_vel = Vector3.ZERO if is_on_floor() else grav_vel.move_toward(Vector3(0, velocity.y - gravity, 0), gravity * delta) grav_vel = Vector3.ZERO if is_on_floor() else grav_vel.move_toward(Vector3(0, velocity.y - gravity, 0), gravity * delta)
return grav_vel return grav_vel
func _jump(delta: float) -> Vector3: func _jump(delta: float) -> Vector3:
if jumping: if jumping:
if is_on_floor(): jump_vel = Vector3(0, sqrt(4 * jump_height * gravity), 0) if is_on_floor(): jump_vel = Vector3(0, sqrt(4 * jump_height * gravity), 0)
@ -137,18 +148,21 @@ func _jump(delta: float) -> Vector3:
jump_vel = Vector3.ZERO if is_on_floor() else jump_vel.move_toward(Vector3.ZERO, gravity * delta) jump_vel = Vector3.ZERO if is_on_floor() else jump_vel.move_toward(Vector3.ZERO, gravity * delta)
return jump_vel return jump_vel
func player_entered_ship(ship_global_position: Vector3, ship: Ship): func player_entered_ship(ship_global_position: Vector3, ship: Ship):
if !is_network_authority: return if !is_network_authority: return
current_ship = ship current_ship = ship
print(ship.ship_id) print(ship.ship_id)
print(global_position) print(global_position)
func player_exited_ship(ship_global_position: Vector3, ship: Ship): func player_exited_ship(ship_global_position: Vector3, ship: Ship):
if !is_network_authority: return if !is_network_authority: return
current_ship = null current_ship = null
print(ship.ship_id) print(ship.ship_id)
print(global_position) print(global_position)
func set_is_piloting(state: bool): func set_is_piloting(state: bool):
if !is_network_authority: return if !is_network_authority: return
is_piloting = state is_piloting = state