|
|
|
|
Reply From: |
exuin |
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.
ahh, i shouldve posted my whole code. it was bits and pieces from other tutorials. ill paste what i have now. currently after my jab animation it freezes. i have no walking animation yet.
Blockquote
extends KinematicBody2D
var movement = Vector2();
var up = Vector2(0, -1);
var speed = 200
var isAttacking = false
func _process(delta):
#button inputs
if Input.is_action_pressed("move_left") && isAttacking == false:
movement.x -= speed;
if Input.is_action_pressed("move_right") && isAttacking == false:
movement.x += speed;
if Input.is_action_just_pressed("attack_jab"):
$animatedsprite.play("jab");
isAttacking = true
movement = move_and_slide(movement, up * delta);
func _on_AnimatedSprite_animation_finished():
if $Animatedsprite.animation == “jab”:
isAttacking = false;
Blockquote
16bit Ktempo | 2021-01-24 08:42
What do you mean by freeze? As in the character stops responding to inputs or the character stops being animated?
the character stop responding to inputs
16bit Ktempo | 2021-01-24 10:11
Are you sure you’re accessing the AnimatedSprite correctly? I see that you have two different capitalizations of it. Are you getting an error message?
i get an error message. it was saying something about “func onAnimationSpriteanimationfinished()” not being linked correctly. i connected that from the node tab. i saw that in tutorial. it worked for the guy that did it. he was makin a mega man like game and was adding a slash animation then returning to idle. i started over in a new project. ive been watching tutorials, but im trying to pick what i can use from each since most ppl make RPG’s or platformers. im making a 2D fighter. this is my current code.
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 _physics_process( _delta):
if Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
elif Input.is_action_pressed(“move_right”):
velocity.x = SPEED
else:
velocity.x = 0
if Input.is_action_pressed("ui_up"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
velocity = move_and_slide(velocity, FLOOR)
this is working. i just have to attempt to set up the jab animation in the code.
16bit Ktempo | 2021-01-24 16:21
Can you just copy and paste the error here?
going bac to my first project, somehow i made 2 scripts with realizing i did. i think thats where the issue is…
but in my debugger im seeing:
“Script inherits from type ‘KinematicBody2D’, do it can’t be instanced in object of type 'Node2D”
and i get a yellow message:
“Missing connected method’_on_AnimatedSprite_animation_finished’for signal’animation_finished’from node’main scene/player 1/AnimatedSprite’ to node ‘main scene/player’.”
16bit Ktempo | 2021-01-24 17:00
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 _physics_process( _delta):
if Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$player.play("walk")
elif Input.is_action_pressed(“move_right”):
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()
16bit Ktempo | 2021-01-25 04:26
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
16bit Ktempo | 2021-01-25 06:51
Well, then remove the signal to prevent the error then.