Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LJ INFINITY |
this is my code:
extends KinematicBody2D
const gravity = 30
export var speed = 120
export var jump_power = 650
var Floor = Vector2(0,-1)
var velocity = Vector2.ZERO
var onground = false
func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
velocity.x = -1
$AnimatedSprite.flip_h = true
elif Input.is_action_pressed("ui_right"):
velocity.x = 1
$AnimatedSprite.flip_h = false
else:
velocity.x = 0
velocity.y += gravity * delta
if Input.is_action_pressed("jump") and onground == true:
velocity.y = -jump_power
onground = false
if is_on_floor():
onground = true
else:
onground = false
velocity = velocity.normalized() * speed
velocity = move_and_slide(velocity,Floor)