enhancing car behavior
This commit is contained in:
@@ -6,6 +6,8 @@ extends RigidBody3D
|
||||
@export var turn_speed := 2.0
|
||||
@export var turn_accel := 8.0
|
||||
@export var lateral_damp := 10.0
|
||||
@export var launch_impulse := 28.0
|
||||
@export var launch_up_impulse := 6.0
|
||||
@export var seat_path: NodePath
|
||||
@export var exit_path: NodePath
|
||||
@export var camera_path: NodePath
|
||||
@@ -27,6 +29,8 @@ func _ready() -> void:
|
||||
interact_area.body_exited.connect(_on_interact_body_exited)
|
||||
if car_camera:
|
||||
car_camera.current = false
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 8
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _driver == null and _nearby_driver != null and Input.is_action_just_pressed("interact"):
|
||||
@@ -56,6 +60,23 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||
var target_turn: float = -input2v.x * turn_speed * speed_factor
|
||||
angular_velocity.y = move_toward(angular_velocity.y, target_turn, turn_accel * state.step)
|
||||
|
||||
if speed_factor > 0.2:
|
||||
var hit_ids := {}
|
||||
for i in state.get_contact_count():
|
||||
var collider := state.get_contact_collider_object(i)
|
||||
if collider is RigidBody3D and collider != self:
|
||||
var collider_id := (collider as Node).get_instance_id()
|
||||
if hit_ids.has(collider_id):
|
||||
continue
|
||||
hit_ids[collider_id] = true
|
||||
var contact_pos := state.get_contact_collider_position(i)
|
||||
var launch_dir := (contact_pos - global_position).normalized()
|
||||
if launch_dir.length() <= 0.001:
|
||||
var normal_world := (global_transform.basis * state.get_contact_local_normal(i)).normalized()
|
||||
launch_dir = normal_world if normal_world.length() > 0.001 else forward.normalized()
|
||||
var impulse := launch_dir * (launch_impulse * speed_factor) + Vector3.UP * launch_up_impulse
|
||||
(collider as RigidBody3D).apply_central_impulse(impulse)
|
||||
|
||||
func _enter_vehicle(player: Node) -> void:
|
||||
if seat == null:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user