probably tab space diff
This commit is contained in:
parent
40f48677f9
commit
66b521a54a
|
|
@ -50,83 +50,83 @@ func _process(delta):
|
|||
set_active(!active)
|
||||
|
||||
func _physics_process(delta:float):
|
||||
_handle_movement(delta)
|
||||
_handle_rotation(delta)
|
||||
_handle_jitter(delta)
|
||||
_handle_movement(delta)
|
||||
_handle_rotation(delta)
|
||||
_handle_jitter(delta)
|
||||
|
||||
func _handle_movement(delta:float):
|
||||
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"))
|
||||
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"))
|
||||
|
||||
if input.length()>1:
|
||||
input = input.normalized()
|
||||
if input.length()>1:
|
||||
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():
|
||||
direction = Vector3.ZERO
|
||||
else:
|
||||
direction *= (direction*max_speed - linear_velocity).length()*max_acceleration
|
||||
if linear_velocity.length() > (linear_velocity + (direction*max_speed - linear_velocity)).length():
|
||||
direction = Vector3.ZERO
|
||||
else:
|
||||
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):
|
||||
var smoothness = min(3, 60.0/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:
|
||||
input_speed = current_mouse_rotation
|
||||
current_mouse_rotation = Vector2.ZERO
|
||||
if current_mouse_rotation.length()>0:
|
||||
input_speed = current_mouse_rotation
|
||||
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:
|
||||
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/-max_angle, 4)
|
||||
elif rotation_speed.y < 0 and pitch.rotation_degrees.x > 0 :
|
||||
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/max_angle, 4)
|
||||
if rotation_speed.y > 0 and pitch.rotation_degrees.x < 0:
|
||||
rotation_speed.y *= 1-pow(pitch.rotation_degrees.x/-max_angle, 4)
|
||||
elif rotation_speed.y < 0 and pitch.rotation_degrees.x > 0 :
|
||||
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))
|
||||
pitch.rotate_x(deg_to_rad(-rotation_speed.y * delta * mouse_sensitivity.y))
|
||||
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))
|
||||
|
||||
func _handle_jitter(delta):
|
||||
loc_noise_spot += Vector3(delta * camera_jitter_speed * location_jitter_speed)
|
||||
rot_noise_spot += Vector3(delta * camera_jitter_speed * angular_jitter_speed)
|
||||
pitch.position = Vector3(
|
||||
noise.get_noise_1d(loc_noise_spot.x),
|
||||
noise.get_noise_1d(loc_noise_spot.y),
|
||||
noise.get_noise_1d(loc_noise_spot.z)
|
||||
) * location_jitter
|
||||
loc_noise_spot += Vector3(delta * camera_jitter_speed * location_jitter_speed)
|
||||
rot_noise_spot += Vector3(delta * camera_jitter_speed * angular_jitter_speed)
|
||||
pitch.position = Vector3(
|
||||
noise.get_noise_1d(loc_noise_spot.x),
|
||||
noise.get_noise_1d(loc_noise_spot.y),
|
||||
noise.get_noise_1d(loc_noise_spot.z)
|
||||
) * location_jitter
|
||||
|
||||
mount.rotation = Vector3(
|
||||
noise.get_noise_1d(rot_noise_spot.x),
|
||||
noise.get_noise_1d(rot_noise_spot.y),
|
||||
noise.get_noise_1d(rot_noise_spot.z)
|
||||
) * angular_jitter
|
||||
mount.rotation = Vector3(
|
||||
noise.get_noise_1d(rot_noise_spot.x),
|
||||
noise.get_noise_1d(rot_noise_spot.y),
|
||||
noise.get_noise_1d(rot_noise_spot.z)
|
||||
) * angular_jitter
|
||||
|
||||
|
||||
func _handle_mouse_input(event:InputEventMouseMotion):
|
||||
if event.relative.length() < mouse_jerk_rejection:
|
||||
current_mouse_rotation = event.relative
|
||||
if event.relative.length() < mouse_jerk_rejection:
|
||||
current_mouse_rotation = event.relative
|
||||
|
||||
func _unhandled_input(event:InputEvent):
|
||||
if active:
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
_handle_mouse_input(event)
|
||||
if active:
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
_handle_mouse_input(event)
|
||||
|
||||
func _on_bed_enter(body):
|
||||
if not crouched:
|
||||
$PlayerAnimationPlayer.queue("crouch")
|
||||
max_speed *= .5
|
||||
crouched = true
|
||||
if not crouched:
|
||||
$PlayerAnimationPlayer.queue("crouch")
|
||||
max_speed *= .5
|
||||
crouched = true
|
||||
|
||||
func _on_bed_exited(body):
|
||||
if crouched:
|
||||
crouched = false
|
||||
$PlayerAnimationPlayer.queue("stand_up")
|
||||
await $PlayerAnimationPlayer.animation_finished
|
||||
max_speed *= 2
|
||||
if crouched:
|
||||
crouched = false
|
||||
$PlayerAnimationPlayer.queue("stand_up")
|
||||
await $PlayerAnimationPlayer.animation_finished
|
||||
max_speed *= 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue