reorganize mech.gd
This commit is contained in:
@@ -31,18 +31,42 @@ func _ready() -> void:
|
||||
_ready_leg_ik(_leg_foot_body_r, _ankle_bone_r)
|
||||
|
||||
|
||||
func _ready_leg_ik(foot_body: Node3D, bone: String) -> void:
|
||||
foot_body.position = (
|
||||
_skeleton.get_bone_global_rest(_skeleton.find_bone(bone)).origin
|
||||
)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
_process_leg_ik(_leg_ik_l, _leg_ik_magnet_l)
|
||||
_process_leg_ik(_leg_ik_r, _leg_ik_magnet_r)
|
||||
_process_position()
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_l)
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_r)
|
||||
|
||||
_mouse_relative = Vector2.ZERO
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
var event_mouse := event as InputEventMouseMotion
|
||||
_mouse_relative = event_mouse.screen_relative
|
||||
else:
|
||||
_mouse_relative = Vector2.ZERO
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
var event_mouse := event as InputEventMouseButton
|
||||
if event_mouse.is_pressed():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
|
||||
func _ready_leg_ik(foot_body: Node3D, bone: String) -> void:
|
||||
foot_body.position = (
|
||||
_skeleton.get_bone_global_rest(_skeleton.find_bone(bone)).origin
|
||||
)
|
||||
|
||||
|
||||
func _process_leg_ik(ik: SkeletonIK3D, ik_magnet: Node3D) -> void:
|
||||
ik.magnet = to_local(ik_magnet.global_position)
|
||||
|
||||
@@ -57,15 +81,6 @@ func _process_position() -> void:
|
||||
global_position = root_position
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_l)
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_r)
|
||||
|
||||
_mouse_relative = Vector2.ZERO
|
||||
|
||||
|
||||
func _handle_leg_moving(mouse_delta: Vector2, foot_body: CharacterBody3D) -> void:
|
||||
var velocity_local := Vector3(
|
||||
0,
|
||||
@@ -74,18 +89,3 @@ func _handle_leg_moving(mouse_delta: Vector2, foot_body: CharacterBody3D) -> voi
|
||||
)
|
||||
foot_body.velocity = transform.basis * velocity_local
|
||||
foot_body.move_and_slide()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
var event_mouse := event as InputEventMouseMotion
|
||||
_mouse_relative = event_mouse.screen_relative
|
||||
else:
|
||||
_mouse_relative = Vector2.ZERO
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
var event_mouse := event as InputEventMouseButton
|
||||
if event_mouse.is_pressed():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
Reference in New Issue
Block a user