add feet falling physics
This commit is contained in:
@@ -18,12 +18,16 @@ class_name Mech extends Node3D
|
||||
@export var _leg_ik_target_r: Node3D
|
||||
@export var _leg_ik_magnet_r: Node3D
|
||||
|
||||
@export_group("Physics")
|
||||
@export var _foot_fall_acceleration: float = 1
|
||||
|
||||
@export_group("Walking")
|
||||
@export var _mouse_walk_sensitivity: float = 1
|
||||
|
||||
var _mouse_relative: Vector2
|
||||
var _is_moving_leg_l:bool
|
||||
var _is_moving_leg_r:bool
|
||||
var _is_moving_leg_l: bool
|
||||
var _is_moving_leg_r: bool
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_leg_ik_l.start()
|
||||
@@ -41,8 +45,13 @@ func _process(_delta: float) -> void:
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if _is_moving_leg_l:
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_l)
|
||||
else:
|
||||
_handle_leg_physics(_leg_foot_body_l)
|
||||
|
||||
if _is_moving_leg_r:
|
||||
_handle_leg_moving(_mouse_relative, _leg_foot_body_r)
|
||||
else:
|
||||
_handle_leg_physics(_leg_foot_body_r)
|
||||
|
||||
_mouse_relative = Vector2.ZERO
|
||||
|
||||
@@ -60,7 +69,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
|
||||
if event_mouse.button_index == MOUSE_BUTTON_LEFT:
|
||||
_is_moving_leg_l = event_mouse.is_pressed()
|
||||
if event_mouse.button_index == MOUSE_BUTTON_RIGHT:
|
||||
@@ -95,3 +104,15 @@ func _handle_leg_moving(mouse_delta: Vector2, foot_body: CharacterBody3D) -> voi
|
||||
)
|
||||
foot_body.velocity = transform.basis * velocity_local
|
||||
foot_body.move_and_slide()
|
||||
foot_body.velocity = Vector3.ZERO
|
||||
|
||||
|
||||
func _handle_leg_physics(foot_body: CharacterBody3D) -> void:
|
||||
if foot_body.is_on_floor():
|
||||
foot_body.velocity = Vector3.ZERO
|
||||
return
|
||||
|
||||
foot_body.velocity.x = 0
|
||||
foot_body.velocity.z = 0
|
||||
foot_body.velocity.y -= _foot_fall_acceleration
|
||||
foot_body.move_and_slide()
|
||||
|
||||
Reference in New Issue
Block a user