Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JPixelArt |
How do I access a certain frame of a specific animation in my player?
I want to make it use the “NO AR” animation on frame 2 of the “Preparando Pul” animation, by activating velocity.y = jump_speed.
CODE:
extends KinematicBody2D
var state_machine
var speed = 100.0
var velocity = Vector2.ZERO
onready var _animated_gun = $MP5
var jump_speed = -350
var grv = 10
func _ready():
state_machine = $AnimationPlayer
func _physics_process(_delta):
velocity.y += grv
if Input.is_action_pressed("ui_left"):
$Sprite.scale.x = -1
$MP5.scale.x = -1
velocity.x = -1 * speed
if Input.is_action_pressed("ui_right"):
$Sprite.scale.x = 1
$MP5.scale.x = 1
velocity.x = 1 * speed
if Input.is_action_pressed("ui_right") || Input.is_action_pressed("ui_left"):
if Input.is_action_pressed("SHIFT"):
speed = 50
state_machine.play("Walking")
_animated_gun.play("MP5_ANDANDO_SHIFT")
else:
state_machine.play("Running")
_animated_gun.play("MP5_CORRENDO")
speed = 100
else:
state_machine.play("Idle")
_animated_gun.play("MP5_IDLE")
if Input.is_action_pressed("ui_up"):
state_machine.play("Preparando Pul")
if state_machine.getFrames() == 2:
state_machine.play("NO AR")
velocity.y = jump_speed
else:
velocity.y += grv
##if state_machine.current_animation == "Preparando Pul":
velocity = velocity.normalized() * speed
move_and_slide(velocity)