generated from krampus/template-godot4
Prop throwing
This commit is contained in:
parent
5d8516398d
commit
7f83fa6244
@ -16,6 +16,9 @@ signal dropped
|
|||||||
## Temporary linear damping for held objects
|
## Temporary linear damping for held objects
|
||||||
@export var hold_damping := 8.0
|
@export var hold_damping := 8.0
|
||||||
|
|
||||||
|
## Impulse force when throwing an object
|
||||||
|
@export var throw_force := 100.0
|
||||||
|
|
||||||
## Temporary collision layer.
|
## Temporary collision layer.
|
||||||
@export_flags_3d_physics var hold_collision_layer := 0b01000000
|
@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:
|
func attach(prop: RigidBody3D, hold_distance: float) -> void:
|
||||||
hold_point.position = Vector3(0, 0, -hold_distance)
|
hold_point.position = Vector3(0, 0, -hold_distance)
|
||||||
|
hold_point.global_basis = global_basis
|
||||||
_held_object = prop
|
_held_object = prop
|
||||||
|
|
||||||
_original_damping = prop.linear_damp
|
_original_damping = prop.linear_damp
|
||||||
@ -58,14 +62,33 @@ func drop() -> void:
|
|||||||
dropped.emit()
|
dropped.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func throw() -> void:
|
||||||
|
var impulse := -global_basis.z.normalized() * throw_force
|
||||||
|
_held_object.apply_central_impulse(impulse)
|
||||||
|
drop()
|
||||||
|
|
||||||
|
|
||||||
func holding_object() -> bool:
|
func holding_object() -> bool:
|
||||||
return !!_held_object
|
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:
|
func _physics_process(delta: float) -> void:
|
||||||
# Object hold action logic
|
# Object hold action logic
|
||||||
if holding_object() and Input.is_action_just_pressed("interact"):
|
if holding_object():
|
||||||
drop()
|
_process_hold_controls()
|
||||||
|
|
||||||
# Held object logic
|
# Held object logic
|
||||||
if not holding_object():
|
if not holding_object():
|
||||||
@ -78,4 +101,4 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
var weight := 1 - exp(-hold_accel * delta)
|
var weight := 1 - exp(-hold_accel * delta)
|
||||||
_held_object.linear_velocity = _held_object.linear_velocity.lerp(diff * hold_speed, weight)
|
_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)
|
||||||
|
@ -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://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"]
|
[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)
|
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"]
|
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"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_s7f0r"]
|
||||||
radius = 0.4
|
radius = 0.4
|
||||||
height = 1.9
|
height = 1.9
|
||||||
@ -689,16 +685,12 @@ unique_name_in_owner = true
|
|||||||
script = ExtResource("11_h0enb")
|
script = ExtResource("11_h0enb")
|
||||||
hold_accel = 40.0
|
hold_accel = 40.0
|
||||||
hold_speed = 20.0
|
hold_speed = 20.0
|
||||||
|
throw_force = 400.0
|
||||||
|
|
||||||
[node name="HoldPoint" type="Marker3D" parent="CameraPosition/CameraPivot/TransformedPosition/CamRumbler/Camera3D/HoldComponent"]
|
[node name="HoldPoint" type="Marker3D" parent="CameraPosition/CameraPivot/TransformedPosition/CamRumbler/Camera3D/HoldComponent"]
|
||||||
unique_name_in_owner = true
|
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"]
|
|
||||||
visible = false
|
|
||||||
mesh = SubResource("SphereMesh_h0enb")
|
|
||||||
skeleton = NodePath("../..")
|
|
||||||
|
|
||||||
[node name="StandingCollider" type="CollisionShape3D" parent="."]
|
[node name="StandingCollider" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0)
|
||||||
shape = SubResource("CapsuleShape3D_s7f0r")
|
shape = SubResource("CapsuleShape3D_s7f0r")
|
||||||
|
@ -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"]]
|
[node name="PhysCrateLong" type="RigidBody3D" groups=["Persistent", "PlasticMaterial"]]
|
||||||
collision_layer = 71
|
collision_layer = 71
|
||||||
collision_mask = 73
|
collision_mask = 73
|
||||||
mass = 200.0
|
mass = 60.0
|
||||||
script = ExtResource("1_q4djj")
|
script = ExtResource("1_q4djj")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
[ext_resource type="Resource" uid="uid://tgac5tnfx56r" path="res://src/world/world_manager.tres" id="2_5kmgb"]
|
[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="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="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://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"]
|
[ext_resource type="PackedScene" uid="uid://brknr57xc2cp0" path="res://src/ui/elements/save_icon/save_icon.tscn" id="7_5kmgb"]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user