I am working on my first project with Godot (and in Gamedev in general). I am now trying to configure animations for my character in an isometric 3d game.
Inside of AnimationPlayerTree, I have an AnimationNodeBlendTree. At the root, I've created a BlendSpace2D. To this blend, I've added a few animations. for example on [0,-1] it is run, on [0,1] it's run backward, [-1,0] its left run, and so on.
Now I am trying to use this logic to trigger an animation:
func play_moving_animation(moving_direction: Vector2, delta: float, player: Player) -> void:
var vector = Vector2(
move_toward(current_moving_direction.x, moving_direction.x, target_animation_speed * delta),
move_toward(current_moving_direction.y, moving_direction.y, target_animation_speed * delta)
)
var rotated = vector.rotated(-player.rotation.y).rotated(player.get_isometric_rotation().y)
human_animation_tree.set("parameters/MovementBlend/blend_position", vector)
current_moving_direction = moving_direction
I think that main issue is with this line:
var rotated = vector.rotated(-player.rotation.y).rotated(player.get_isometric_rotation().y)
It doesn't rotate my vector correctly coz all my animations only work properly when I am getting moving_direction = Vector2.UP and mouse is above the player
Here is a bit of context
- I call is like this:
model.play_moving_animation(Input.get_vector("left", "right", "forward", "back"), delta, player)
- In player I have
func get_isometric_rotation() -> Vector3:
return camera.global_rotation
func get_mouse_on_floor_position() -> Vector2:
var mouse_pos = get_viewport().get_mouse_position()
var camera_pos = camera.global_position
var ray_dir = camera.project_ray_normal(mouse_pos)
var t = -camera_pos.y / ray_dir.y
var world_pos = camera_pos + ray_dir * t
return Vector2(world_pos.x, world_pos.z)
- My character already rotates properly following the mouse:
func handle_rotation(delta: float) -> void:
var position = (Vector2(player.position.x, player.position.z) - player.get_mouse_on_floor_position()).normalized()
var angle = -position.angle() + PI/2
player.rotation.y = rotate_toward(player.rotation.y, angle, delta * character_rotation_speed)