arm movement
This commit is contained in:
parent
f3e161d48c
commit
f16e42a8d0
4 changed files with 49 additions and 19 deletions
BIN
pickaxe_arm.blend
Normal file
BIN
pickaxe_arm.blend
Normal file
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://n05pnykd3tff"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://n05pnykd3tff"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dgm3241ceqpim" path="res://scenes/body.tscn" id="1_eeca8"]
|
||||
|
||||
|
@ -21,6 +21,12 @@ size = Vector3(50, 1, 50)
|
|||
[sub_resource type="BoxShape3D" id="BoxShape3D_0lkv2"]
|
||||
size = Vector3(50, 1, 50)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_6hnpm"]
|
||||
size = Vector3(25, 1, 100)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_qcnmp"]
|
||||
size = Vector3(25, 1, 100)
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
@ -58,4 +64,15 @@ skeleton = NodePath("../..")
|
|||
[node name="CollisionShape3D" type="CollisionShape3D" parent="World/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_0lkv2")
|
||||
|
||||
[node name="StaticBody3D2" type="StaticBody3D" parent="World"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 50, -18)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="World/StaticBody3D2"]
|
||||
mesh = SubResource("BoxMesh_6hnpm")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="World/StaticBody3D2"]
|
||||
shape = SubResource("BoxShape3D_qcnmp")
|
||||
|
||||
[node name="Body" parent="World" instance=ExtResource("1_eeca8")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7, 0)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class_name Arm extends Node3D
|
||||
|
||||
@export var action: StringName
|
||||
@onready var camera: Camera3D = $"../../Camera3D"
|
||||
@onready var target: Marker3D = $Target
|
||||
|
||||
@export var action: StringName
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
@ -13,10 +15,17 @@ func _process(delta: float) -> void:
|
|||
pass
|
||||
|
||||
|
||||
func _arm_enabled(arm):
|
||||
print_debug("enabled!")
|
||||
pass
|
||||
|
||||
func _arm_disabled(arm):
|
||||
print_debug("disabled!")
|
||||
pass
|
||||
func update_target_pos() -> void:
|
||||
var mouse_pos: Vector2 = camera.get_window().get_mouse_position()
|
||||
|
||||
var origin: Vector3 = camera.project_ray_origin(mouse_pos)
|
||||
var dir: Vector3 = origin + (camera.project_ray_normal(mouse_pos) * 100)
|
||||
|
||||
var world_space: PhysicsDirectSpaceState3D = camera.get_window().world_3d.direct_space_state
|
||||
var ray_query = PhysicsRayQueryParameters3D.create(origin, dir)
|
||||
var collision: Dictionary = world_space.intersect_ray(ray_query)
|
||||
|
||||
if collision == null: return
|
||||
|
||||
var arm_target_pos: Vector3 = collision["position"]
|
||||
target.global_position = arm_target_pos
|
||||
|
|
|
@ -1,21 +1,25 @@
|
|||
class_name Body extends Node3D
|
||||
|
||||
@export var arms: Array[Arm]
|
||||
@export var pull_strength: float = 5.0
|
||||
|
||||
signal arm_enabled(arm)
|
||||
signal arm_disabled(arm)
|
||||
|
||||
var active_arm: Arm
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
for arm in arms:
|
||||
arm_enabled.connect(arm._arm_enabled)
|
||||
arm_disabled.connect(arm._arm_disabled)
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
for arm in arms:
|
||||
if Input.is_action_just_pressed(arm.action):
|
||||
arm_enabled.emit(arm)
|
||||
if Input.is_action_pressed(arm.action):
|
||||
active_arm = arm
|
||||
return
|
||||
if Input.is_action_just_released(arm.action):
|
||||
arm_disabled.emit(arm)
|
||||
active_arm = null
|
||||
return
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if active_arm == null: return
|
||||
|
||||
active_arm.update_target_pos()
|
||||
|
|
Loading…
Add table
Reference in a new issue