Determine which BlendSpace2d point is chosen given a Vector2

Godot Version

4.2.1

Question

My question is whether it’s possible to query a BlendSpace2D to find out what point (animation) would be selected given a particular Vector2.

So, the way BlendSpace2D works (in general) is: you set the blend value to a particular vector, and then the node works out which point in the blend space that vector corresponds to. As well as that, when everything is set up appropriately, it plays the animation assigned to that point.

This can mean, for example, that pressing up+right moves the sprite up and to the right, and the blend space chooses the walk right animation for movement in this direction.

I would like to do some things in game based on which way the character is facing at a given time. As such, I need to track what the facing is. Unfortunately, neither the AnimationTree, nor the AnimationPlayer give signals for animations in state machines when travel is used. I have added methods to the call track for each animation and this is fine as workaround, but…

What I’d really like to do, is to query the blend space to determine which point would be selected, if I pass in a particular Vector2. Does anyone know if there is a way to do this?

Have you tried using the current_animation property of AnimationPlayer?

Nope, just tested it. It doesn’t return any value at all.

My understanding on this, from reading around, is that AnimationTree reaches in and accesses the resources within the AnimationPlayer directly. This means that, in a lot of cases, the AnimationPlayer node object doesn’t know anything about what is happening - meaning that its properties aren’t updated, its signals don’t fire, etc…

Then I would create a string var that changes when you set the parameters for the AnimationTree, like “crouching”, “running”, etc. You put that string in a match(string) and do different stuff for each case.

You could also use ifs with the AnimationTree parameters like…
if AnimationTree[…/is_running]: do something

Thank you for these suggestions.

One issue I have with the existing blendspace2d is that the facing is not always consistent on diagonals (left | right + up | down pairings).

I found a way to fix this by extending the blendspace further by 0.1 on the y (positive and negative) and then adjusting the “down” and “up” nodes out to the edges. The blendspace then prioritises left/right, so there is consistency in the facing on diagonal movement. I’ll just check button presses and retain facing as state based on which buttons are pressed. It’s kind of duplicating the work of the blendspace, but it’ll do as a workaround…

1 Like