Lets use animation and mesh in Godot.

When we do export we want to export in glTF file and include animations:

in code: we want to use AnimationPlayer included in glb:

#Player.gd
@onready var anim_player = $Pivot/Character/AnimationPlayer

func _physics_process(delta):
	var direction = Vector3.ZERO

	if Input.is_action_pressed("move_right"):
		direction.z += 1
	if Input.is_action_pressed("move_left"):
		direction.z -= 1
	if Input.is_action_pressed("move_back"):
		direction.x -= 1
	if Input.is_action_pressed("move_forward"):
		direction.x += 1

	if direction != Vector3.ZERO:
		# Rotate input direction 45 degrees around Y-axis to align with isometric world
		var angle_45 = deg_to_rad(45)
		var rotated_direction = Vector3(
			direction.x * cos(angle_45) - direction.z * sin(angle_45),
			0,
			direction.x * sin(angle_45) + direction.z * cos(angle_45)
		).normalized()

		# Face movement direction
		$Pivot.basis = Basis.looking_at(rotated_direction)

		# Play walking animation
		if not anim_player.is_playing():
			anim_player.play("Walking_001")

		# Apply horizontal velocity
		target_velocity.x = rotated_direction.x * speed
		target_velocity.z = rotated_direction.z * speed
	else:
		# Stop animation if idle
		if anim_player.is_playing():
			anim_player.stop()
		target_velocity.x = 0
		target_velocity.z = 0

	# Apply gravity
	if not is_on_floor():
		target_velocity.y -= fall_acceleration * delta
	else:
		target_velocity.y = 0

	velocity = target_velocity
	move_and_slide()

end result:

its backwards 🙂

Blender and Godot use different axis systems:

EngineForward AxisUp Axis
Blender+Y+Z
Godot-Z+Y

Thats what we solve next time.


Comments

Vastaa

Sähköpostiosoitettasi ei julkaista. Pakolliset kentät on merkitty *