feat: adding better animations
This commit is contained in:
@@ -11,27 +11,59 @@ func build_ragdoll(color: Color) -> void:
|
||||
# Create bodies
|
||||
torso_body = _create_body(Vector3(0.4, 0.7, 0.25), mat, Vector3(0, 1.15, 0), 20.0)
|
||||
var head_body = _create_body(Vector3(0.25, 0.25, 0.25), mat, Vector3(0, 1.65, 0), 5.0)
|
||||
var arm_l_body = _create_body(Vector3(0.12, 0.65, 0.12), mat, Vector3(-0.28, 1.15, 0), 5.0)
|
||||
var arm_r_body = _create_body(Vector3(0.12, 0.65, 0.12), mat, Vector3(0.28, 1.15, 0), 5.0)
|
||||
var leg_l_body = _create_body(Vector3(0.15, 0.8, 0.15), mat, Vector3(-0.12, 0.4, 0), 8.0)
|
||||
var leg_r_body = _create_body(Vector3(0.15, 0.8, 0.15), mat, Vector3(0.12, 0.4, 0), 8.0)
|
||||
|
||||
var upper_arm_l_body = _create_body(Vector3(0.12, 0.35, 0.12), mat, Vector3(-0.28, 1.275, 0), 3.0)
|
||||
var lower_arm_l_body = _create_body(Vector3(0.1, 0.35, 0.1), mat, Vector3(-0.28, 0.925, 0), 2.0)
|
||||
var upper_arm_r_body = _create_body(Vector3(0.12, 0.35, 0.12), mat, Vector3(0.28, 1.275, 0), 3.0)
|
||||
var lower_arm_r_body = _create_body(Vector3(0.1, 0.35, 0.1), mat, Vector3(0.28, 0.925, 0), 2.0)
|
||||
|
||||
var thigh_l_body = _create_body(Vector3(0.15, 0.45, 0.15), mat, Vector3(-0.12, 0.625, 0), 5.0)
|
||||
var calf_l_body = _create_body(Vector3(0.13, 0.45, 0.13), mat, Vector3(-0.12, 0.175, 0), 3.0)
|
||||
var thigh_r_body = _create_body(Vector3(0.15, 0.45, 0.15), mat, Vector3(0.12, 0.625, 0), 5.0)
|
||||
var calf_r_body = _create_body(Vector3(0.13, 0.45, 0.13), mat, Vector3(0.12, 0.175, 0), 3.0)
|
||||
|
||||
add_child(torso_body)
|
||||
add_child(head_body)
|
||||
add_child(arm_l_body)
|
||||
add_child(arm_r_body)
|
||||
add_child(leg_l_body)
|
||||
add_child(leg_r_body)
|
||||
add_child(upper_arm_l_body)
|
||||
add_child(lower_arm_l_body)
|
||||
add_child(upper_arm_r_body)
|
||||
add_child(lower_arm_r_body)
|
||||
add_child(thigh_l_body)
|
||||
add_child(calf_l_body)
|
||||
add_child(thigh_r_body)
|
||||
add_child(calf_r_body)
|
||||
|
||||
# Need to wait a frame for paths to be valid before creating joints
|
||||
call_deferred("_setup_joints", head_body, arm_l_body, arm_r_body, leg_l_body, leg_r_body)
|
||||
call_deferred("_setup_joints", head_body,
|
||||
upper_arm_l_body, lower_arm_l_body,
|
||||
upper_arm_r_body, lower_arm_r_body,
|
||||
thigh_l_body, calf_l_body,
|
||||
thigh_r_body, calf_r_body)
|
||||
|
||||
func _setup_joints(head_body, arm_l_body, arm_r_body, leg_l_body, leg_r_body) -> void:
|
||||
func _setup_joints(head_body,
|
||||
u_arm_l, l_arm_l,
|
||||
u_arm_r, l_arm_r,
|
||||
thigh_l, calf_l,
|
||||
thigh_r, calf_r) -> void:
|
||||
|
||||
# Neck
|
||||
_create_joint(torso_body, head_body, Vector3(0, 1.5, 0))
|
||||
_create_joint(torso_body, arm_l_body, Vector3(-0.28, 1.45, 0))
|
||||
_create_joint(torso_body, arm_r_body, Vector3(0.28, 1.45, 0))
|
||||
_create_joint(torso_body, leg_l_body, Vector3(-0.12, 0.8, 0))
|
||||
_create_joint(torso_body, leg_r_body, Vector3(0.12, 0.8, 0))
|
||||
|
||||
# Shoulders
|
||||
_create_joint(torso_body, u_arm_l, Vector3(-0.28, 1.45, 0))
|
||||
_create_joint(torso_body, u_arm_r, Vector3(0.28, 1.45, 0))
|
||||
|
||||
# Hips
|
||||
_create_joint(torso_body, thigh_l, Vector3(-0.12, 0.85, 0))
|
||||
_create_joint(torso_body, thigh_r, Vector3(0.12, 0.85, 0))
|
||||
|
||||
# Elbows (Hinge, bends forwards only)
|
||||
_create_hinge(u_arm_l, l_arm_l, Vector3(-0.28, 1.10, 0), -PI * 0.8, 0.0)
|
||||
_create_hinge(u_arm_r, l_arm_r, Vector3(0.28, 1.10, 0), -PI * 0.8, 0.0)
|
||||
|
||||
# Knees (Hinge, bends backwards only)
|
||||
_create_hinge(thigh_l, calf_l, Vector3(-0.12, 0.40, 0), 0.0, PI * 0.8)
|
||||
_create_hinge(thigh_r, calf_r, Vector3(0.12, 0.40, 0), 0.0, PI * 0.8)
|
||||
|
||||
func apply_initial_velocities(linear_vel: Vector3, impulse: Vector3) -> void:
|
||||
for child in get_children():
|
||||
@@ -93,3 +125,28 @@ func _create_joint(node_a: RigidBody3D, node_b: RigidBody3D, pos: Vector3) -> vo
|
||||
joint.set_flag_z(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
|
||||
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, -PI * 0.2)
|
||||
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, PI * 0.2)
|
||||
|
||||
func _create_hinge(node_a: RigidBody3D, node_b: RigidBody3D, pos: Vector3, lower_lim: float, upper_lim: float) -> void:
|
||||
var joint = Generic6DOFJoint3D.new()
|
||||
add_child(joint)
|
||||
joint.position = pos
|
||||
joint.node_a = node_a.get_path()
|
||||
joint.node_b = node_b.get_path()
|
||||
|
||||
joint.set_flag_x(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
|
||||
joint.set_flag_y(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
|
||||
joint.set_flag_z(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
|
||||
|
||||
# Allow X rotation for the hinge (knee/elbow)
|
||||
joint.set_flag_x(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
|
||||
joint.set_param_x(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, lower_lim)
|
||||
joint.set_param_x(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, upper_lim)
|
||||
|
||||
# Lock Y and Z
|
||||
joint.set_flag_y(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
|
||||
joint.set_param_y(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, 0.0)
|
||||
joint.set_param_y(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, 0.0)
|
||||
|
||||
joint.set_flag_z(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
|
||||
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, 0.0)
|
||||
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, 0.0)
|
||||
|
||||
Reference in New Issue
Block a user