0 votes

if Input.is.actionpressed("attackjab"):
animationsprite.animation = "jab"

im new to coding and im not sure what to look up.
ill be looking stuff up in the mean time.

im making a 2D fighter, and i dont see many others doing it.

Godot version v3.2.3
in Engine by (12 points)

2 Answers

+1 vote

You only posted two lines of code, but I'm guessing that you have some code that sets the animation to an idle animation or no animation at all if there's no button pressed. A simple solution to this would be to have a boolean that keeps track of whether the player is attacking or not and not play the idle/no animation if the player is attacking.

by (7,769 points)

Okay well can you put the correct scripts on the correct nodes?

You have the script on a Node2D instead of a KinematicBody2D so you should probably move it to the correct place.

probably, but ive already started a duplicate project. currently having the same scenario. i can do my jab animation only when i jump.

extends KinematicBody2D

const SPEED = 100
const GRAVITY = 10
const JUMP_POWER = -150
const FLOOR = Vector2(0, -1)

var velocity = Vector2()

var on_ground = false

func physicsprocess( _delta):

if Input.is_action_pressed("ui_left"):
    velocity.x = -SPEED
    $player.play("walk")

elif Input.isactionpressed("moveright"):
velocity.x = SPEED
$player.play("walk")
else:
if on
ground == true:
$player.play("idle")
velocity.x = 0

if Input.is_action_pressed("ui_up"):
    if on_ground == true:
        velocity.y = JUMP_POWER
        on_ground = false

if Input.is_action_pressed("attack_jab"):
    $player.play("jab")



velocity.y += GRAVITY

if is_on_floor():
    on_ground = true
else:
    on_ground = false 

velocity = move_and_slide(velocity, FLOOR)

this is my current script. all animations play properly except for jab..

this is the current error message:

E 0:00:59.239   emit_signal: Error calling method from signal 'animation_finished': 'KinematicBody2D(player.gd)::_on_player_animation_finished': Method not found..

<C++ Source> core/object.cpp:1260 @ emit_signal()

Looks like you connected the signal but deleted the function that it was connected to. You need to recreate the function.

it wasnt doing anything when i applied it

Well, then remove the signal to prevent the error then.

+1 vote

Try this

animationsprite.play("jab")

Check out the docs for more info on AnimationPlayer.

https://docs.godotengine.org/en/stable/classes/class_animationplayer.html

by (130 points)
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 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.