lorge boi
This commit is contained in:
parent
1233f76869
commit
f7671a216d
13 changed files with 217 additions and 111 deletions
|
@ -1,34 +1,31 @@
|
|||
class_name Arm extends Node3D
|
||||
@tool
|
||||
|
||||
@onready var camera: Camera3D = $"../../Camera3D"
|
||||
@onready var target: Marker3D = $Target
|
||||
@onready var ik_skeleton: SkeletonIK3D = $Skeleton3D/SkeletonIK3D
|
||||
class_name Arm extends SkeletonIK3D
|
||||
|
||||
@onready var ik_target = get_node(target_node)
|
||||
@onready var skeleton: Skeleton3D = get_parent_skeleton()
|
||||
|
||||
@export var action: StringName
|
||||
@export var move_speed: float = 1.5
|
||||
|
||||
var input_dir: Vector2
|
||||
var tip_bone_trans: Transform3D
|
||||
|
||||
func _ready() -> void:
|
||||
#$Skeleton3D/PhysicalBoneSimulator3D.physical_bones_start_simulation()
|
||||
pass
|
||||
modification_processed.connect(_on_modification_processed)
|
||||
|
||||
start()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
#ik_skeleton.start()
|
||||
pass
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
input_dir = event.relative
|
||||
|
||||
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"]
|
||||
print(collision)
|
||||
target.global_position.z = arm_target_pos.z
|
||||
target.global_position.y = arm_target_pos.y
|
||||
func update_target_pos(delta: float) -> void:
|
||||
ik_target.global_position.z -= input_dir.x * delta * move_speed
|
||||
ik_target.global_position.y -= input_dir.y * delta * move_speed
|
||||
input_dir = Vector2.ZERO
|
||||
|
||||
func _on_modification_processed() -> void:
|
||||
var tip_bone_id: int = skeleton.find_bone(tip_bone)
|
||||
tip_bone_trans = skeleton.get_bone_global_pose(tip_bone_id)
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
class_name Body extends Node3D
|
||||
|
||||
@export var arms: Array[Arm]
|
||||
@export var pull_strength: float = 5.0
|
||||
|
||||
var active_arm: Arm
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
for arm in arms:
|
||||
if Input.is_action_pressed(arm.action):
|
||||
active_arm = arm
|
||||
return
|
||||
if Input.is_action_just_released(arm.action):
|
||||
active_arm = null
|
||||
return
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if active_arm == null: return
|
||||
|
||||
active_arm.update_target_pos()
|
4
scripts/main.gd
Normal file
4
scripts/main.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
55
scripts/robot.gd
Normal file
55
scripts/robot.gd
Normal file
|
@ -0,0 +1,55 @@
|
|||
class_name Body extends Node3D
|
||||
|
||||
@export var arms: Array[Arm]
|
||||
@export var body_offset: float = 0.25
|
||||
@export var skeleton: Skeleton3D
|
||||
@export var body_bone: StringName
|
||||
@onready var previous_position: Vector3 = global_position
|
||||
|
||||
var active_arm: Arm
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
for arm in arms:
|
||||
if Input.is_action_pressed(arm.action):
|
||||
active_arm = arm
|
||||
return
|
||||
if Input.is_action_just_released(arm.action):
|
||||
active_arm = null
|
||||
return
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if active_arm == null: return
|
||||
|
||||
active_arm.update_target_pos(delta)
|
||||
|
||||
var avg_tip_pos: Vector3
|
||||
var avg_tip_basis: Basis
|
||||
|
||||
for arm in arms:
|
||||
var tip_bone_global_pos: Vector3 = skeleton.to_global(arm.tip_bone_trans.origin)
|
||||
#var tip_bone_global_basis: Basis = arm.tip_bone_tras.basis
|
||||
|
||||
avg_tip_pos += tip_bone_global_pos
|
||||
|
||||
#avg_tip_basis.x += tip_bone_global_basis.x
|
||||
#avg_tip_basis.y += tip_bone_global_basis.y
|
||||
#avg_tip_basis.z += tip_bone_global_basis.z
|
||||
|
||||
avg_tip_pos /= arms.size()
|
||||
#avg_tip_basis.x /= arms.size()
|
||||
#avg_tip_basis.y /= arms.size()
|
||||
#avg_tip_basis.z /= arms.size()
|
||||
|
||||
#skeleton.global_position = avg_tip_pos
|
||||
#var m = MeshInstance3D.new()
|
||||
var body_bone_id: int = skeleton.find_bone(body_bone)
|
||||
var body_bone_transform = skeleton.get_bone_global_pose(body_bone_id)
|
||||
var velocity = global_position - previous_position
|
||||
print(global_position, previous_position, velocity, avg_tip_pos)
|
||||
var global_pos = avg_tip_pos + velocity * body_offset
|
||||
body_bone_transform.origin = global_pos
|
||||
skeleton.set_bone_global_pose(body_bone_id, body_bone_transform)
|
||||
previous_position = global_pos
|
||||
#m.global_position = avg_tip_pos
|
||||
#skeleton.global_basis = avg_tip_basis
|
Loading…
Add table
Add a link
Reference in a new issue