fix ocer-compensation of framerate
This commit is contained in:
parent
63397c7424
commit
4b906e0fe4
|
|
@ -31,97 +31,97 @@ var crouched:bool = false
|
||||||
|
|
||||||
|
|
||||||
func set_active(activate):
|
func set_active(activate):
|
||||||
if !is_inside_tree(): return
|
if !is_inside_tree(): return
|
||||||
if activate:
|
if activate:
|
||||||
camera.make_current()
|
camera.make_current()
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||||
sleeping = active
|
sleeping = active
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
if active:
|
if active:
|
||||||
set_active(active)
|
set_active(active)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta:float):
|
func _physics_process(delta:float):
|
||||||
_handle_movement(delta)
|
_handle_movement(delta)
|
||||||
_handle_rotation(delta)
|
_handle_rotation(delta)
|
||||||
_handle_jitter(delta)
|
_handle_jitter(delta)
|
||||||
|
|
||||||
func _handle_movement(delta:float):
|
func _handle_movement(delta:float):
|
||||||
var input:Vector2 = Vector2(Input.get_action_strength("player_right") - Input.get_action_strength("player_left"),
|
var input:Vector2 = Vector2(Input.get_action_strength("player_right") - Input.get_action_strength("player_left"),
|
||||||
Input.get_action_strength("player_backwards")*0.8 - Input.get_action_strength("player_forwards"))
|
Input.get_action_strength("player_backwards")*0.8 - Input.get_action_strength("player_forwards"))
|
||||||
|
|
||||||
if input.length()>1:
|
if input.length()>1:
|
||||||
input = input.normalized()
|
input = input.normalized()
|
||||||
|
|
||||||
var direction: Vector3 = Vector3(input.x, 0, input.y)
|
var direction: Vector3 = Vector3(input.x, 0, input.y)
|
||||||
|
|
||||||
direction = yaw.global_transform.basis.x * direction.x + transform.basis.y * direction.y + yaw.global_transform.basis.z * direction.z
|
direction = yaw.global_transform.basis.x * direction.x + transform.basis.y * direction.y + yaw.global_transform.basis.z * direction.z
|
||||||
|
|
||||||
if linear_velocity.length() > (linear_velocity + (direction*max_speed - linear_velocity)).length():
|
if linear_velocity.length() > (linear_velocity + (direction*max_speed - linear_velocity)).length():
|
||||||
direction = Vector3.ZERO
|
direction = Vector3.ZERO
|
||||||
else:
|
else:
|
||||||
direction *= (direction*max_speed - linear_velocity).length()*max_acceleration
|
direction *= (direction*max_speed - linear_velocity).length()*max_acceleration
|
||||||
|
|
||||||
linear_damp = damp * max(0.5, 1 - input.length())
|
linear_damp = damp * max(0.5, 1 - input.length())
|
||||||
|
|
||||||
apply_central_impulse(direction*delta)
|
apply_central_impulse(direction*delta)
|
||||||
|
|
||||||
func _handle_rotation(delta:float):
|
func _handle_rotation(delta:float):
|
||||||
var smoothness = 60/Engine.get_frames_per_second()
|
var smoothness = min(3, 60.0/Engine.get_frames_per_second())
|
||||||
|
|
||||||
var input_speed = Vector2( Input.get_action_strength("look_right")-Input.get_action_strength("look_left"), Input.get_action_strength("look_down")-Input.get_action_strength("look_up")) * gamepad_response
|
var input_speed = Vector2( Input.get_action_strength("look_right")-Input.get_action_strength("look_left"), Input.get_action_strength("look_down")-Input.get_action_strength("look_up")) * gamepad_response
|
||||||
|
|
||||||
if current_mouse_rotation.length()>0:
|
if current_mouse_rotation.length()>0:
|
||||||
input_speed = current_mouse_rotation
|
input_speed = current_mouse_rotation
|
||||||
current_mouse_rotation = Vector2.ZERO
|
current_mouse_rotation = Vector2.ZERO
|
||||||
|
|
||||||
rotation_speed = rotation_speed * (1-mouse_jerk*smoothness) + input_speed * mouse_jerk * smoothness
|
rotation_speed = rotation_speed * (1-mouse_jerk*smoothness) + input_speed * mouse_jerk * smoothness
|
||||||
|
|
||||||
if rotation_speed.y > 0 and pitch.rotation_degrees.x < 0:
|
if rotation_speed.y > 0 and pitch.rotation_degrees.x < 0:
|
||||||
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/-max_angle, 4)
|
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/-max_angle, 4)
|
||||||
elif rotation_speed.y < 0 and pitch.rotation_degrees.x > 0 :
|
elif rotation_speed.y < 0 and pitch.rotation_degrees.x > 0 :
|
||||||
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/max_angle, 4)
|
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/max_angle, 4)
|
||||||
|
|
||||||
yaw.rotate_y(deg_to_rad(-rotation_speed.x * delta * mouse_sensitivity.x))
|
yaw.rotate_y(deg_to_rad(-rotation_speed.x * delta * mouse_sensitivity.x))
|
||||||
pitch.rotate_x(deg_to_rad(-rotation_speed.y * delta * mouse_sensitivity.y))
|
pitch.rotate_x(deg_to_rad(-rotation_speed.y * delta * mouse_sensitivity.y))
|
||||||
|
|
||||||
func _handle_jitter(delta):
|
func _handle_jitter(delta):
|
||||||
loc_noise_spot += Vector3(delta * camera_jitter_speed * location_jitter_speed)
|
loc_noise_spot += Vector3(delta * camera_jitter_speed * location_jitter_speed)
|
||||||
rot_noise_spot += Vector3(delta * camera_jitter_speed * angular_jitter_speed)
|
rot_noise_spot += Vector3(delta * camera_jitter_speed * angular_jitter_speed)
|
||||||
pitch.position = Vector3(
|
pitch.position = Vector3(
|
||||||
noise.get_noise_1d(loc_noise_spot.x),
|
noise.get_noise_1d(loc_noise_spot.x),
|
||||||
noise.get_noise_1d(loc_noise_spot.y),
|
noise.get_noise_1d(loc_noise_spot.y),
|
||||||
noise.get_noise_1d(loc_noise_spot.z)
|
noise.get_noise_1d(loc_noise_spot.z)
|
||||||
) * location_jitter
|
) * location_jitter
|
||||||
|
|
||||||
mount.rotation = Vector3(
|
mount.rotation = Vector3(
|
||||||
noise.get_noise_1d(rot_noise_spot.x),
|
noise.get_noise_1d(rot_noise_spot.x),
|
||||||
noise.get_noise_1d(rot_noise_spot.y),
|
noise.get_noise_1d(rot_noise_spot.y),
|
||||||
noise.get_noise_1d(rot_noise_spot.z)
|
noise.get_noise_1d(rot_noise_spot.z)
|
||||||
) * angular_jitter
|
) * angular_jitter
|
||||||
|
|
||||||
|
|
||||||
func _handle_mouse_input(event:InputEventMouseMotion):
|
func _handle_mouse_input(event:InputEventMouseMotion):
|
||||||
if event.relative.length() < mouse_jerk_rejection:
|
if event.relative.length() < mouse_jerk_rejection:
|
||||||
current_mouse_rotation = event.relative
|
current_mouse_rotation = event.relative
|
||||||
|
|
||||||
func _unhandled_input(event:InputEvent):
|
func _unhandled_input(event:InputEvent):
|
||||||
if active:
|
if active:
|
||||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||||
_handle_mouse_input(event)
|
_handle_mouse_input(event)
|
||||||
|
|
||||||
|
|
||||||
func _on_bed_enter(body):
|
func _on_bed_enter(body):
|
||||||
if not crouched:
|
if not crouched:
|
||||||
$PlayerAnimationPlayer.queue("crouch")
|
$PlayerAnimationPlayer.queue("crouch")
|
||||||
max_speed *= .5
|
max_speed *= .5
|
||||||
crouched = true
|
crouched = true
|
||||||
|
|
||||||
func _on_bed_exited(body):
|
func _on_bed_exited(body):
|
||||||
if crouched:
|
if crouched:
|
||||||
crouched = false
|
crouched = false
|
||||||
$PlayerAnimationPlayer.queue("stand_up")
|
$PlayerAnimationPlayer.queue("stand_up")
|
||||||
await $PlayerAnimationPlayer.animation_finished
|
await $PlayerAnimationPlayer.animation_finished
|
||||||
max_speed *= 2
|
max_speed *= 2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue