3D Character model mangled after falling from platform
Asked Answered
D

1

0

Hi, im trying to debug when my character falls off the platform the 3d model gets mangled while its falling, but it stays in the air at the height when it started to fall off. It does not happen when i trigger jump animation, and in air animation. Only when i am in walk or run animation mode. Where should i strart looking to debug this?




Here is the jump animation

extends CharacterBody3D

var SPEED = 0
var JUMP_VELOCITY = 4.5
var SPEED_VELOCITY = 10
var push_force = 1.0
var h_sensitivity = 0.20
var v_sensitivity = 0.20
var walking_speed = 0.55
var running_speed = 4.0
var isInAir = false
var isWalking = false
var isRunning = false


# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

func _ready():

	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	pass
	
func _input(event):
	if event is InputEventMouseMotion:
		rotate_y(deg_to_rad(-event.relative.x * h_sensitivity))
		$rig.rotate_y(deg_to_rad(event.relative.x * h_sensitivity))
		pass
		
func _physics_process(delta):
	if Input.is_action_pressed("run"):

		SPEED = running_speed
	else: 

		SPEED = walking_speed

	if Input.is_action_pressed("test"):
		
		$AnimationTree.set("parameters/conditions/landed",false)		
		$AnimationTree.set("parameters/conditions/jump",true)
		
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta
		isInAir = true

	else:

		if isInAir == true:
			isInAir = false
			$AnimationTree.set("parameters/JumpLanded/TimeScale/scale",6.0)
			$AnimationTree.set("parameters/conditions/jump",false)
			$AnimationTree.set("parameters/conditions/landed",true)
			$AnimationTree.set("parameters/conditions/idle",true)

	# Handle Jump.
	if Input.is_action_just_pressed("jump") and is_on_floor() and !isInAir:
		velocity.y = JUMP_VELOCITY
		isInAir = true
		$AnimationTree.set("parameters/JumpStart/TimeScale/scale",6.0)
		$AnimationTree.set("parameters/conditions/idle",false)
		$AnimationTree.set("parameters/conditions/landed",false)
		$AnimationTree.set("parameters/conditions/jump",true)
		
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("left", "right", "forward", "backward")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	
	if direction:
		$rig.look_at(position + direction)
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED

	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	var iw_blend = (velocity.length() - walking_speed) / walking_speed
	var wr_blend = (velocity.length() - walking_speed) / (running_speed- walking_speed)
	

	$AnimationTree.set("parameters/conditions/idle", (!isInAir && is_on_floor()))
	
	isWalking = !isInAir && (float("%.2f" % (velocity.length())) >0 )&& (float("%.2f" % (velocity.length())) <= walking_speed)
	isRunning = !isInAir && (float("%.2f" % (velocity.length())) >walking_speed )
	
	if float("%.2f" % (velocity.length())) <= walking_speed:
		$AnimationTree.set("parameters/iwr/Blend3/blend_amount", iw_blend)
	else:
		$AnimationTree.set("parameters/iwr/Blend3/blend_amount", wr_blend)

	move_and_slide()
Darlenedarline answered 18/9, 2023 at 14:27 Comment(0)
D
0

Special thanks to matrix godot members, it turned out to be that multiple animations was trying to play so the bones were doing multiple rotations.

i added animation stree setter in the not is_on_floor statement

	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta
		isInAir = true
		$AnimationTree.set("parameters/conditions/idle",false) # <-------------------------
		$AnimationTree.set("parameters/conditions/landed",false)	 # <-------------------------
		$AnimationTree.set("parameters/conditions/jump",true) # <-------------------------
	else:

And now animations are switching when character is falling

Darlenedarline answered 19/9, 2023 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.