![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Trazmaball |
extends KinematicBody2D
const SPEED = 35
const GRAVITY = 10
const JUMP_POWER = -135
const FLOOR = Vector2(0, -1)
var velocity = Vector2()
var on_ground = false
func _physics_process(delta):
if Input. is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.play("Moving")
$AnimatedSprite.flip_h = false
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
elif Input. is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.play("Moving")
$AnimatedSprite.flip_h = true
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
else:
velocity.x = 0
if on_ground == true:
$AnimatedSprite.play("Idle")
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
if velocity.y < 0:
$AnimatedSprite.play("Jump")
else:
$AnimatedSprite.play("Falling")
velocity = move_and_slide(velocity, FLOOR)
the line: velocity = move_and_slide(velocity, FLOOR)
It has identation, shouldn’t it be outside the previous if-else?
estebanmolca | 2019-12-28 09:30