++
This commit is contained in:
parent
93aa46f863
commit
8244b1e090
1 changed files with 13 additions and 17 deletions
|
|
@ -27,8 +27,6 @@ var bound_offset = Vector2()
|
||||||
|
|
||||||
var state = STATE.WALKING
|
var state = STATE.WALKING
|
||||||
|
|
||||||
var _oldtf = Transform()
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
@ -38,7 +36,7 @@ func _input(event):
|
||||||
if not paused:
|
if not paused:
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
camera_base.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
|
camera_base.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
|
||||||
|
|
||||||
var x_delta = event.relative.y * mouse_sensitivity
|
var x_delta = event.relative.y * mouse_sensitivity
|
||||||
if camera_x_rotation + x_delta > -90 and camera_x_rotation + x_delta < 90:
|
if camera_x_rotation + x_delta > -90 and camera_x_rotation + x_delta < 90:
|
||||||
camera.rotate_x(deg2rad(-x_delta))
|
camera.rotate_x(deg2rad(-x_delta))
|
||||||
|
|
@ -50,24 +48,24 @@ func grounded():
|
||||||
func _integrate_forces(physics_state):
|
func _integrate_forces(physics_state):
|
||||||
# State machine
|
# State machine
|
||||||
state = swap_state()
|
state = swap_state()
|
||||||
|
|
||||||
if not paused:
|
if not paused:
|
||||||
var acc = Vector3()
|
var acc = Vector3()
|
||||||
var direction = Vector3()
|
var direction = Vector3()
|
||||||
var camera_base_basis = camera.get_global_transform().basis
|
var camera_base_basis = camera.get_global_transform().basis
|
||||||
var mod = SPRINT_MOD if Input.is_action_pressed("sprint") else 1
|
var mod = SPRINT_MOD if Input.is_action_pressed("sprint") else 1
|
||||||
|
|
||||||
if Input.is_action_pressed("forward"):
|
if Input.is_action_pressed("forward"):
|
||||||
direction -= camera_base_basis.z #forward is negative in Godot
|
direction -= camera_base_basis.z #forward is negative in Godot
|
||||||
if Input.is_action_pressed("backward"):
|
if Input.is_action_pressed("backward"):
|
||||||
direction += camera_base_basis.z
|
direction += camera_base_basis.z
|
||||||
|
|
||||||
# Strafe
|
# Strafe
|
||||||
if Input.is_action_pressed("left"):
|
if Input.is_action_pressed("left"):
|
||||||
direction -= camera_base_basis.x
|
direction -= camera_base_basis.x
|
||||||
if Input.is_action_pressed("right"):
|
if Input.is_action_pressed("right"):
|
||||||
direction += camera_base_basis.x
|
direction += camera_base_basis.x
|
||||||
|
|
||||||
match state:
|
match state:
|
||||||
STATE.WALKING:
|
STATE.WALKING:
|
||||||
if Input.is_action_just_pressed("jump") and grounded():
|
if Input.is_action_just_pressed("jump") and grounded():
|
||||||
|
|
@ -83,13 +81,13 @@ func _integrate_forces(physics_state):
|
||||||
acc = direction * SPEED * mod
|
acc = direction * SPEED * mod
|
||||||
STATE.FLOATING:
|
STATE.FLOATING:
|
||||||
physics_state.add_central_force(Vector3.DOWN * 9.8)
|
physics_state.add_central_force(Vector3.DOWN * 9.8)
|
||||||
|
|
||||||
var wave = ocean.get_wave(translation.x, translation.z)
|
var wave = ocean.get_wave(translation.x, translation.z)
|
||||||
var wave_height = wave.y
|
var wave_height = wave.y
|
||||||
var height = translation.y
|
var height = translation.y
|
||||||
|
|
||||||
acc = direction * SPEED * mod
|
acc = direction * SPEED * mod
|
||||||
|
|
||||||
if height < wave_height:
|
if height < wave_height:
|
||||||
var buoyancy = clamp((wave_height - height) / 0.001, 0, 1) * 5
|
var buoyancy = clamp((wave_height - height) / 0.001, 0, 1) * 5
|
||||||
physics_state.add_central_force(Vector3(0, 9.8 * buoyancy, 0))
|
physics_state.add_central_force(Vector3(0, 9.8 * buoyancy, 0))
|
||||||
|
|
@ -98,14 +96,12 @@ func _integrate_forces(physics_state):
|
||||||
STATE.SAILING:
|
STATE.SAILING:
|
||||||
self.transform = bound_object.transform
|
self.transform = bound_object.transform
|
||||||
self.translate(bound_offset)
|
self.translate(bound_offset)
|
||||||
|
|
||||||
physics_state.add_central_force(acc * mass)
|
physics_state.add_central_force(acc * mass)
|
||||||
|
|
||||||
# emit signal - playerinfo_updated
|
# emit signal - playerinfo_updated
|
||||||
var tf = $Head/Camera.get_global_transform_interpolated()
|
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
|
||||||
if tf != _oldtf:
|
|
||||||
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
|
|
||||||
_oldtf = tf
|
|
||||||
|
|
||||||
|
|
||||||
func swap_state():
|
func swap_state():
|
||||||
|
|
@ -128,7 +124,7 @@ func swap_state():
|
||||||
new_state = STATE.WALKING
|
new_state = STATE.WALKING
|
||||||
if translation.y < wave_height - 0.1:
|
if translation.y < wave_height - 0.1:
|
||||||
new_state = STATE.DIVING
|
new_state = STATE.DIVING
|
||||||
|
|
||||||
return new_state
|
return new_state
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue