Prop throwing

This commit is contained in:
Rob Kelly 2025-07-07 11:18:56 -06:00
parent 5d8516398d
commit 7f83fa6244
4 changed files with 30 additions and 15 deletions

View File

@ -16,6 +16,9 @@ signal dropped
## Temporary linear damping for held objects
@export var hold_damping := 8.0
## Impulse force when throwing an object
@export var throw_force := 100.0
## Temporary collision layer.
@export_flags_3d_physics var hold_collision_layer := 0b01000000
@ -35,6 +38,7 @@ var _original_collision_mask: int
func attach(prop: RigidBody3D, hold_distance: float) -> void:
hold_point.position = Vector3(0, 0, -hold_distance)
hold_point.global_basis = global_basis
_held_object = prop
_original_damping = prop.linear_damp
@ -58,14 +62,33 @@ func drop() -> void:
dropped.emit()
func throw() -> void:
var impulse := -global_basis.z.normalized() * throw_force
_held_object.apply_central_impulse(impulse)
drop()
func holding_object() -> bool:
return !!_held_object
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and holding_object():
print(event)
func _process_hold_controls() -> void:
if Input.is_action_just_pressed("interact"):
drop()
elif Input.is_action_just_pressed("fire"):
throw()
func _physics_process(delta: float) -> void:
# Object hold action logic
if holding_object() and Input.is_action_just_pressed("interact"):
drop()
if holding_object():
_process_hold_controls()
# Held object logic
if not holding_object():
@ -78,4 +101,4 @@ func _physics_process(delta: float) -> void:
var weight := 1 - exp(-hold_accel * delta)
_held_object.linear_velocity = _held_object.linear_velocity.lerp(diff * hold_speed, weight)
_held_object.global_basis = _held_object.global_basis.slerp(global_basis, weight)
_held_object.global_basis = _held_object.global_basis.slerp(hold_point.global_basis, weight)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=68 format=3 uid="uid://bwe2jdmvinhqd"]
[gd_scene load_steps=67 format=3 uid="uid://bwe2jdmvinhqd"]
[ext_resource type="Script" uid="uid://buwh0g1ga2aka" path="res://src/player/player.gd" id="1_npueo"]
[ext_resource type="Script" uid="uid://cx1yt0drthpw3" path="res://src/player/camera_controller.gd" id="2_veeqv"]
@ -173,10 +173,6 @@ nodes/timescale/node = SubResource("AnimationNodeTimeScale_8ydov")
nodes/timescale/position = Vector2(1240, 120)
node_connections = [&"blend", 0, &"still_anim", &"blend", 1, &"bob_anim", &"output", 0, &"timescale", &"sfx_add", 0, &"blend", &"sfx_add", 1, &"sfx_anim", &"timescale", 0, &"sfx_add"]
[sub_resource type="SphereMesh" id="SphereMesh_h0enb"]
radius = 0.05
height = 0.1
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_s7f0r"]
radius = 0.4
height = 1.9
@ -689,16 +685,12 @@ unique_name_in_owner = true
script = ExtResource("11_h0enb")
hold_accel = 40.0
hold_speed = 20.0
throw_force = 400.0
[node name="HoldPoint" type="Marker3D" parent="CameraPosition/CameraPivot/TransformedPosition/CamRumbler/Camera3D/HoldComponent"]
unique_name_in_owner = true
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"]
visible = false
mesh = SubResource("SphereMesh_h0enb")
skeleton = NodePath("../..")
[node name="StandingCollider" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0)
shape = SubResource("CapsuleShape3D_s7f0r")

View File

@ -26,7 +26,7 @@ points = PackedVector3Array(0.375, 0.149961, 0.75, 0.375, -0.15001, 0.75, 0.375,
[node name="PhysCrateLong" type="RigidBody3D" groups=["Persistent", "PlasticMaterial"]]
collision_layer = 71
collision_mask = 73
mass = 200.0
mass = 60.0
script = ExtResource("1_q4djj")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]

View File

@ -4,7 +4,7 @@
[ext_resource type="Resource" uid="uid://tgac5tnfx56r" path="res://src/world/world_manager.tres" id="2_5kmgb"]
[ext_resource type="PackedScene" uid="uid://byvjsvavbg5xe" path="res://src/ui/menus/pause_menu/pause_menu.tscn" id="2_6fy3g"]
[ext_resource type="Resource" uid="uid://0i72bf8ip1lx" path="res://src/world/spook_manager.tres" id="3_l0av5"]
[ext_resource type="PackedScene" uid="uid://bov4ok76woyc" path="res://levels/ghost_ship/ghost_ship.tscn" id="4_5kmgb"]
[ext_resource type="PackedScene" uid="uid://dc4tts6342cuj" path="res://levels/prop_test/prop_test.tscn" id="4_5kmgb"]
[ext_resource type="PackedScene" uid="uid://c0uitm5cg88h1" path="res://src/ui/menus/kill_screen/kill_screen.tscn" id="6_l0av5"]
[ext_resource type="PackedScene" uid="uid://brknr57xc2cp0" path="res://src/ui/elements/save_icon/save_icon.tscn" id="7_5kmgb"]