Smooth animation change using blendspace2d

MeshuggenerMeshuggener Posts: 6Member
edited June 7 in 3D

I am using the BlendTree in my AnimationTree, and I put a BlendSpace2D to have my character walk, I find that the animation between walking directions is not blended, but instead a lot more snappy, which looks weird considering that it's the direction of a walk cycle. What are my options for making the animation have a more smooth transition between Front Left and Front walking animations?


Tags :

Answers

  • DemiBoiiDemiBoii Posts: 10Member

    I am also having this issue. I know in theory what the solution is, I am still putting together a solution.

    In theory, it is because you are assigning hard values that dont transition, so -1s, 0s and 1s would be an example. But you have to have it slide between -1 and 1 with your animation to blend properly. I am working on a quick fix now, and I will post it here when I have it fleshed out. :)

  • MeshuggenerMeshuggener Posts: 6Member

    Great! :), I know that if you don't use the animation tree, but just the player, there is an option for you to set the time it takes to switch to each animation, which makes the changing movement really nice, ofc without the benefits of the animation tree. Unfortunately, I have not been able to find such an option for the 2D blend space :'(. But I'm stoked to hear about what your solution is though :)

  • MegalomaniakMegalomaniak Posts: 2,645Admin

    I wonder if you couldn't use the call method track in animation player to be able to set up a key/event for a method to change the necessary value...

  • DemiBoiiDemiBoii Posts: 10Member
    edited June 20

    Okay I have this figured out. So firstly you are looking to interpolate between these states. I have done some code in relation to my own character controller with a BlendSpace2D and I will post the relevant code below

    So I utilize these variables and initialize the walk_transition (which is the current value) in the _ready function, then through the controller's directional function I grab the "target value" (which is the movement_state, or the value being interpolated to), then in the animation handler function I actually do the interpolation and use the walk_transition value as the blendspace value.

    #ANIMATION VARIABLES
    onready var animation_tree = get_node("AnimationTree")
    onready var animation_mode = animation_tree.get("parameters/playback")
    var movement_state : Vector2
    var walk_transition : Vector2
    export var transition_speed : float = 5
    
    func_ready():
        walk_transition = Vector2(0, 0) #Initialize walk transition vector.
    
    func _physics_process(delta):
        _handle_movement(delta)
        _handle_animation(delta)
    
    func _handle_movement(delta):
        movement_state = Vector2()
    
        if can_move:
            #DIRECTIONAL MOVEMENT
            if Input.is_action_pressed("move_forward"):
                movement_state.y += 1
            if Input.is_action_pressed("move_backward"):
                movement_state.y += 1 #Change to -= 1 when walk_b animation is implemented
            if Input.is_action_pressed("move_left"):
                movement_state.x -= 1
            if Input.is_action_pressed("move_right"):
                movement_state.x += 1
    
    func _handle_animation(delta):
        #DIRECTIONAL MOVEMENT
        walk_transition = walk_transition.linear_interpolate(movement_state, acceleration * delta)
        animation_tree.set("parameters/movement_state/blend_position", walk_transition)
    

    As stated, I only put the relevant pieces in this comment, if anyone is interested in the character controller for their own projects, I am more than happy to share it. If you have any question, let me know and I will help where I can.

  • MegalomaniakMegalomaniak Posts: 2,645Admin

    @DemiBoii said:
    As stated, I only put the relevant pieces in this comment, if anyone is interested in the character controller for their own projects, I am more than happy to share it.

    I'm sure that would deserve it's own topic in the resource section. :)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file