Hooking up animations, and tweaking car behavior
This commit is contained in:
parent
d8138fbe69
commit
b2eb85fdf1
@ -189,6 +189,7 @@ bones/63/position = Vector3(7.93632e-09, 0.1572156, -2.6982683e-10)
|
|||||||
bones/63/rotation = Quaternion(0.28907102, 0.031904068, 0.014082117, 0.9566723)
|
bones/63/rotation = Quaternion(0.28907102, 0.031904068, 0.014082117, 0.9566723)
|
||||||
bones/64/position = Vector3(7.567915e-10, 0.099999994, -3.2595668e-09)
|
bones/64/position = Vector3(7.567915e-10, 0.099999994, -3.2595668e-09)
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
shape = SubResource("SphereShape3D_mx8sn")
|
shape = SubResource("SphereShape3D_mx8sn")
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="Player"]
|
[node name="Camera3D" type="Camera3D" parent="Player"]
|
||||||
|
|||||||
@ -57,7 +57,10 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
|||||||
linear_velocity = forward_vel + lateral_vel
|
linear_velocity = forward_vel + lateral_vel
|
||||||
|
|
||||||
var speed_factor: float = clamp(abs(new_forward_speed) / drive_speed, 0.0, 1.0)
|
var speed_factor: float = clamp(abs(new_forward_speed) / drive_speed, 0.0, 1.0)
|
||||||
var target_turn: float = -input2v.x * turn_speed * speed_factor
|
var turn_input := input2v.x
|
||||||
|
if new_forward_speed < -0.1:
|
||||||
|
turn_input = -turn_input
|
||||||
|
var target_turn: float = turn_input * turn_speed * speed_factor
|
||||||
angular_velocity.y = move_toward(angular_velocity.y, target_turn, turn_accel * state.step)
|
angular_velocity.y = move_toward(angular_velocity.y, target_turn, turn_accel * state.step)
|
||||||
|
|
||||||
if speed_factor > 0.2:
|
if speed_factor > 0.2:
|
||||||
|
|||||||
@ -28,9 +28,16 @@ var _vehicle_collision_layer := 0
|
|||||||
var _vehicle_collision_mask := 0
|
var _vehicle_collision_mask := 0
|
||||||
var _vehicle_original_parent: Node = null
|
var _vehicle_original_parent: Node = null
|
||||||
var _light_was_on := false
|
var _light_was_on := false
|
||||||
|
var _jump_triggered := false
|
||||||
@onready var _flashlight: SpotLight3D = $SpotLight3D
|
@onready var _flashlight: SpotLight3D = $SpotLight3D
|
||||||
|
@onready var _anim_player: AnimationPlayer = find_child("AnimationPlayer", true, false) as AnimationPlayer
|
||||||
|
@onready var _model_root: Node3D = find_child("TestCharAnimated", true, false) as Node3D
|
||||||
|
|
||||||
@export var camera_follow_speed := 10.0
|
@export var camera_follow_speed := 10.0
|
||||||
|
@export var anim_idle_name := "Idle"
|
||||||
|
@export var anim_walk_name := "Walk"
|
||||||
|
@export var anim_jump_name := "Jump"
|
||||||
|
@export var anim_walk_speed_threshold := 0.25
|
||||||
|
|
||||||
var jump_sound = preload("res://assets/audio/jump.ogg")
|
var jump_sound = preload("res://assets/audio/jump.ogg")
|
||||||
var audio_player = AudioStreamPlayer.new()
|
var audio_player = AudioStreamPlayer.new()
|
||||||
@ -128,6 +135,7 @@ func _integrate_forces(state):
|
|||||||
current_number_of_jumps = (current_number_of_jumps + 1) % 2
|
current_number_of_jumps = (current_number_of_jumps + 1) % 2
|
||||||
linear_velocity.y = JUMP_SPEED
|
linear_velocity.y = JUMP_SPEED
|
||||||
audio_player.play()
|
audio_player.play()
|
||||||
|
_jump_triggered = true
|
||||||
|
|
||||||
if cam:
|
if cam:
|
||||||
var target_yaw := global_transform.basis.get_euler().y
|
var target_yaw := global_transform.basis.get_euler().y
|
||||||
@ -137,6 +145,9 @@ func _integrate_forces(state):
|
|||||||
cam.global_position = cam.global_position.lerp(target_pos, camera_follow_speed * state.step)
|
cam.global_position = cam.global_position.lerp(target_pos, camera_follow_speed * state.step)
|
||||||
cam.global_rotation = Vector3(_camera_pitch, _camera_yaw, 0.0)
|
cam.global_rotation = Vector3(_camera_pitch, _camera_yaw, 0.0)
|
||||||
|
|
||||||
|
_update_animation(on_floor, state.linear_velocity)
|
||||||
|
_jump_triggered = false
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if _in_vehicle:
|
if _in_vehicle:
|
||||||
return
|
return
|
||||||
@ -165,6 +176,26 @@ func zoom_camera(factor):
|
|||||||
var new_fov = cam.fov * factor
|
var new_fov = cam.fov * factor
|
||||||
cam.fov = clamp(new_fov, MIN_FOV, MAX_FOV)
|
cam.fov = clamp(new_fov, MIN_FOV, MAX_FOV)
|
||||||
|
|
||||||
|
func _update_animation(on_floor: bool, velocity: Vector3) -> void:
|
||||||
|
if _anim_player == null:
|
||||||
|
return
|
||||||
|
var horizontal_speed := Vector3(velocity.x, 0.0, velocity.z).length()
|
||||||
|
if _jump_triggered and _anim_player.has_animation(anim_jump_name):
|
||||||
|
if _anim_player.current_animation != anim_jump_name:
|
||||||
|
_anim_player.play(anim_jump_name)
|
||||||
|
return
|
||||||
|
if not on_floor and _anim_player.has_animation(anim_jump_name):
|
||||||
|
if _anim_player.current_animation != anim_jump_name:
|
||||||
|
_anim_player.play(anim_jump_name)
|
||||||
|
return
|
||||||
|
if horizontal_speed > anim_walk_speed_threshold and _anim_player.has_animation(anim_walk_name):
|
||||||
|
if _anim_player.current_animation != anim_walk_name:
|
||||||
|
_anim_player.play(anim_walk_name)
|
||||||
|
return
|
||||||
|
if _anim_player.has_animation(anim_idle_name):
|
||||||
|
if _anim_player.current_animation != anim_idle_name:
|
||||||
|
_anim_player.play(anim_idle_name)
|
||||||
|
|
||||||
func enter_vehicle(_vehicle: Node, seat: Node3D, vehicle_camera: Camera3D) -> void:
|
func enter_vehicle(_vehicle: Node, seat: Node3D, vehicle_camera: Camera3D) -> void:
|
||||||
_in_vehicle = true
|
_in_vehicle = true
|
||||||
freeze = true
|
freeze = true
|
||||||
@ -174,6 +205,8 @@ func enter_vehicle(_vehicle: Node, seat: Node3D, vehicle_camera: Camera3D) -> vo
|
|||||||
_vehicle_original_parent = get_parent()
|
_vehicle_original_parent = get_parent()
|
||||||
_light_was_on = _flashlight.visible
|
_light_was_on = _flashlight.visible
|
||||||
_flashlight.visible = false
|
_flashlight.visible = false
|
||||||
|
if _model_root:
|
||||||
|
_model_root.visible = false
|
||||||
if seat:
|
if seat:
|
||||||
reparent(seat, true)
|
reparent(seat, true)
|
||||||
global_transform = seat.global_transform
|
global_transform = seat.global_transform
|
||||||
@ -192,6 +225,8 @@ func exit_vehicle(exit_point: Node3D, vehicle_camera: Camera3D) -> void:
|
|||||||
reparent(_vehicle_original_parent, true)
|
reparent(_vehicle_original_parent, true)
|
||||||
_vehicle_original_parent = null
|
_vehicle_original_parent = null
|
||||||
_flashlight.visible = _light_was_on
|
_flashlight.visible = _light_was_on
|
||||||
|
if _model_root:
|
||||||
|
_model_root.visible = true
|
||||||
if exit_point:
|
if exit_point:
|
||||||
global_transform = exit_point.global_transform
|
global_transform = exit_point.global_transform
|
||||||
if vehicle_camera:
|
if vehicle_camera:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user