Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LifeRips |
Here is the code: please help!
extends KinematicBody2D
const SPEED = 100
const GRAVITY = 10
const JUMP_POWER = -250
const FLOOR = Vector2(0, -1)
var isAttacking = false
var velocity = Vector2()
var on_ground = false
func _physics_process(delta):
if Input.is_action_pressed("ui_right") && isAttacking == false:
velocity.x = SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = false
if Input.is_action_pressed("ui_left") && isAttacking == false:
velocity.x = -SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0
if on_ground == true:
if isAttacking ==false:
$AnimatedSprite.play("Idle")
if Input.is_action_pressed("ui_up"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
if Input.is_action_just_pressed("Attack"):
if on_ground == true:
$AnimatedSprite.play("Attack")
isAttacking = true
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y < 0:
$AnimatedSprite.play("Jump")
else:
$AnimatedSprite.play("Fall")
velocity = move_and_slide(velocity, FLOOR)
func _on_AnimatedSprite_animation_finished():
if $AnimatedSprite.animation == "Attack":
isAttacking = false
Because gdscript
is indent-sensitive, it’s really difficult to point out potential script problems in unformatted code. Please edit your post and format the code. To do that, just select all of the code and press the { }
button in the editor’s toolbar.
jgodfrey | 2020-05-13 13:08
Hi, thanks for that.
LifeRips | 2020-05-13 17:01