I Have a AnimatedSprite and another Player and I want to press on a key and the player attack and hit the other there is my code if you want `extends KinematicBody2D
var collision = 0
const UP = Vector2(0, -1)
const GRAVITY = 20
var SPEED = 200
const JUMPHEIGHT = -400
var motion = Vector2()
var attack = 0
var health
var jumpCount = 0
export var extraJumps = 1
var jumpForce = -400
func _physicsprocess(delta):
motion.y += GRAVITY
var friction = false
if Input.isactionpressed("uiright"):
motion.x = SPEED
$Sprite.play("Walk")
$Sprite.fliph = false
elif Input.isactionpressed("uileft"):
motion.x = -SPEED
$Sprite.play("Walk")
$Sprite.fliph = true
else:
motion.x = 0
$Sprite.play("Idle")
if Input.isactionjustpressed("uiup") && jumpCount < extraJumps:
motion.y = jumpForce
jumpCount += 1
$Jump.play()
if isonfloor():
jumpCount = 0
motion = moveandslide(motion, UP)
pass
if Input.isactionjustpressed("dash"):
dash()
if SPEED == 400 and friction == false:
$Sprite.play("Dash")
if Input.isactionjustpressed("attack"):
attack1()
if attack == 1 and onArea2Dareaentered(Area2D) and collision == 1 :
$Sprite.play("Attack")
$Sprite.stop(true)
func dash():
SPEED = 400
$Timer.start()
$Dash.play()
func onTimer_timeout():
SPEED = 200
func onArea2Dareaentered(Area2D):
health = 10
func attack1():
attack = 1
$Sprite.play("Attack")
$Sprite.pause_mode`