generated from krampus/template-godot4
Held objects integrate linear velocity rather than integrating position directly
This commit is contained in:
parent
b7843659fa
commit
9fe591d92a
@ -4,6 +4,9 @@ extends Node3D
|
|||||||
## Held object position lerp acceleration.
|
## Held object position lerp acceleration.
|
||||||
@export var hold_accel := 20.0
|
@export var hold_accel := 20.0
|
||||||
|
|
||||||
|
## Held object position velocity scale.
|
||||||
|
@export var hold_speed := 12.0
|
||||||
|
|
||||||
## The maximum distance the object may be from the hold point before breaking the hold.
|
## The maximum distance the object may be from the hold point before breaking the hold.
|
||||||
@export var max_distance := 3.0
|
@export var max_distance := 3.0
|
||||||
|
|
||||||
@ -23,8 +26,6 @@ var _original_damping: float
|
|||||||
var _original_collision_layer: int
|
var _original_collision_layer: int
|
||||||
var _original_collision_mask: int
|
var _original_collision_mask: int
|
||||||
|
|
||||||
var _linear_velocity := Vector3.ZERO
|
|
||||||
|
|
||||||
@onready var interact_ray: RayCast3D = %InteractRay
|
@onready var interact_ray: RayCast3D = %InteractRay
|
||||||
@onready var hold_point: Marker3D = %HoldPoint
|
@onready var hold_point: Marker3D = %HoldPoint
|
||||||
|
|
||||||
@ -47,9 +48,7 @@ func drop() -> void:
|
|||||||
_held_object.linear_damp = _original_damping
|
_held_object.linear_damp = _original_damping
|
||||||
_held_object.collision_layer = _original_collision_layer
|
_held_object.collision_layer = _original_collision_layer
|
||||||
_held_object.collision_mask = _original_collision_mask
|
_held_object.collision_mask = _original_collision_mask
|
||||||
_held_object.linear_velocity = _linear_velocity
|
|
||||||
_held_object = null
|
_held_object = null
|
||||||
_linear_velocity = Vector3.ZERO
|
|
||||||
|
|
||||||
|
|
||||||
func holding_object() -> bool:
|
func holding_object() -> bool:
|
||||||
@ -76,12 +75,6 @@ func _physics_process(delta: float) -> void:
|
|||||||
drop()
|
drop()
|
||||||
return
|
return
|
||||||
|
|
||||||
var held_object_last_position := _held_object.global_position
|
|
||||||
|
|
||||||
var weight := 1 - exp(-hold_accel * delta)
|
var weight := 1 - exp(-hold_accel * delta)
|
||||||
_held_object.global_position = _held_object.global_position.lerp(
|
_held_object.linear_velocity = _held_object.linear_velocity.lerp(diff * hold_speed, weight)
|
||||||
hold_point.global_position, weight
|
|
||||||
)
|
|
||||||
_held_object.global_basis = _held_object.global_basis.slerp(global_basis, weight)
|
_held_object.global_basis = _held_object.global_basis.slerp(global_basis, weight)
|
||||||
|
|
||||||
_linear_velocity = (_held_object.global_position - held_object_last_position) / delta
|
|
||||||
|
@ -690,6 +690,7 @@ unique_name_in_owner = true
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)
|
||||||
|
|
||||||
[node name="DebugHoldPoint" type="MeshInstance3D" parent="CameraPosition/CameraPivot/TransformedPosition/CamRumbler/Camera3D/HoldComponent/HoldPoint"]
|
[node name="DebugHoldPoint" type="MeshInstance3D" parent="CameraPosition/CameraPivot/TransformedPosition/CamRumbler/Camera3D/HoldComponent/HoldPoint"]
|
||||||
|
visible = false
|
||||||
mesh = SubResource("SphereMesh_h0enb")
|
mesh = SubResource("SphereMesh_h0enb")
|
||||||
skeleton = NodePath("../..")
|
skeleton = NodePath("../..")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user