-1

im trying to make a 3d fighting game, when i start it the player can move around like normal, but after a few seconds the player just freezes, the animations work fine, but the player will just freeze in place.

i looked through the code a bunch of times but i cant find what's causing it, plz help

Code:

extends KinematicBody

onready var anim = $PlayerANIM/AnimationPlayer

export var speed = 10
const ACCEL = 15.0
const AIR_ACCEL = 9.0
const JUMP_SPEED = 15

var velocity = Vector3.ZERO
var velocity_info = Vector3.ZERO
var current_vel = Vector3.ZERO
var snap = Vector3.ZERO
var gravity = -40
var can_run = true

var dir = Vector3.ZERO

func play_anim(dir):
    if anim.is_playing() == false:
        anim.play("IDLE")
    if Input.is_action_just_pressed("a") or Input.is_action_just_pressed("d") and can_run:
        anim.stop()
        anim.play("RUN")
    if Input.is_action_just_released("a") or Input.is_action_just_released("d") and can_run:
        anim.stop()
    

func _physics_process(delta):
    
    #MOVEMENT
    dir = Vector3.ZERO
    
    if Input.is_action_pressed("d") and can_run:
        rotation_degrees = Vector3(0,0,0)
        if anim.is_playing() == false:
            anim.play("RUN")
        dir += global_transform.basis.x
    if Input.is_action_pressed("a") and can_run:
        rotation_degrees = Vector3(0,180,0)
        if anim.is_playing() == false:
            anim.play("RUN")
        dir += global_transform.basis.x
    if Input.is_action_just_pressed("Punch") and $PunchTimer.is_stopped():
        anim.stop()
        anim.play("PUNCH")
        $PunchTimer.start()
        can_run = false
    if Input.is_action_just_pressed("Kick") and $KickTimer.is_stopped():
        anim.stop()
        anim.play("KICK")
        $KickTimer.start()
        can_run = false
    if Input.is_action_just_released("a") or Input.is_action_just_released("d"):
        anim.stop()
    if Input.is_action_just_pressed("space") and is_on_floor():
        #velocity.y = 15
        anim.play("ROLL")
        $RollTimer.start()
        
        
    var target_vel = dir * speed
    
    var accel = ACCEL if is_on_floor() else AIR_ACCEL
    current_vel = current_vel.linear_interpolate(target_vel, accel * delta)

    velocity.x = current_vel.x
    velocity.z = current_vel.z
    

    velocity.y += gravity *delta
    
    move_and_slide_with_snap(velocity, snap, Vector3.UP, true, 4, deg2rad(45))
    play_anim(dir)
    
    
    


func _on_PunchTimer_timeout():
    can_run = true


func _on_KickTimer_timeout():
    can_run = true


func _on_RollTimer_timeout():
    pass

  • I only have some debug advice for you: put some labels on screen where you can see the values of `dir`, `target_vel`, `current_vel` and `velocity`, so you can figure out what is going wrong. – Theraot Oct 05 '22 at 22:15

1 Answers1

0

I guess you need to change Input.is_action_just_pressed("action_name") to Input_is_actions_pressed("action_name"). The difference is that first functions returns 'true' only once while you pressing the button (which is good, for example, when you make pistol shooting), and second one returns 'true' all the time you pressing the button.