0 votes

I don't know how to make my jump animation work in my code and besides it doesn't work it also makes my jump code not work.

Here´s my code:

extends KinematicBody

var verticalvelocity = 0
var gravity = 50
var direction = Vector3.FORWARD
var velocity = Vector3.ZERO
var strafe
dir = Vector3.ZERO

var jumpmagnitude = 25
var jump
blend = "parameters/jumpblend/blendposition"
var agtransition = "parameters/agtransition/current"
var agtransitionactive = "parameters/jump_blend/acitve"

var fligthmagnitude = 2
var velocity
fly = 0

var movementspeed = 0
var walk
speed = 3
var runspeed = 12
var acceleration = 7
var angular
acceleration = 7
var superspeed = 50
var speed
increase_increment = 1

func physicsprocess(delta):
if Input.isactionpressed("Forward") || Input.isactionpressed("Backward") || Input.isactionpressed("Left") || Input.isactionpressed("Right"):

    var h_rot = $Camroot/h.global_transform.basis.get_euler().y 

    direction = Vector3(Input.get_action_strength("Left") - Input.get_action_strength("Right"),
                Input.get_action_strength("Forward") - Input.get_action_strength("Backward")).rotated(Vector3.UP,h_rot).normalized()

    if Input.is_action_pressed("Sprint"):
        movement_speed = run_speed
        $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), 1 , delta * acceleration))
        $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), 0 , delta * acceleration))
        movement_speed = walk_speed
else :
    $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), -1 , delta * acceleration))
    movement_speed = 0

# faz com que o botão que foi pressionado ative uma ação e se for pressionado de novo desativa a ação

if is_on_floor():

    if $AnimationTree.set(ag_transition,1):
        if $AnimationTree.get("ag_transition_active"):
            if Input.is_action_pressed("Jump"):
                vertical_velocity = jump_magnitude 

        else :
            $AnimationTree.set(jump_blend, lerp($AnimationTree.get(jump_blend), vertical_velocity/jump_magnitude, delta * 10 ))

if gravity <0:
    gravity = 50

if Input.is_action_just_pressed("Flight"):
    if gravity == 0:
        gravity = 50
        vertical_velocity = 0
        run_speed =12
        walk_speed = 3
        gravity = 0
        vertical_velocity = delta * gravity 
        run_speed = 50
        walk_speed = 5

if gravity ==0 and !is_on_floor():
    if Input.is_action_pressed("Up"):
        velocity.y += fligth_magnitude * 2
    if Input.is_action_pressed("E"):
                velocity.y -= fligth_magnitude * 2
    elif is_on_floor():
        velocity.y = 0

velocity = lerp(velocity,direction * movement_speed, delta * acceleration)

move_and_slide(velocity + Vector3.UP * vertical_velocity,Vector3.UP)

if !is_on_floor():
    vertical_velocity -= gravity * delta 
    vertical_velocity = 0

$SimplePlayerarma.rotation.y = lerp_angle($SimplePlayerarma.rotation.y,atan2(direction.x,direction.z), delta * angular_acceleration)
Godot version Godot Engine v3.3.2.
in Engine by (21 points)

I can see you're assigning values to the parameters of the AnimationTree just fine but your entire code without much else makes it difficult to figure out what's happening.

Can you give more details besides "not work"? Do any of your animations still play when you select the AnimationTree and try to activate the animations in the AnimationTree window on the bottom?

Also, have you tried following any specific tutorials with an AnimationTree before?

https://youtu.be/oWmY9A04O70 this is the tutorial I try to follow. And yes my other animations are working just fine

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.