Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | exuin |
See title.
Here is the code I have controlling the character. Also, after the character disappears off-screen, the debug window hangs and refuses to close.
extends KinematicBody2D
const WALK_SPEED = 100
const RUN_SPEED = 200
const JUMP_STRENGTH = 100
const GRAVITY = 10
var velocity = Vector2()
func get_input():
velocity.x = 0
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if is_running:
velocity *= RUN_SPEED
else:
velocity *= WALK_SPEED
func _physics_process(delta):
get_input()
velocity.y += GRAVITY * delta
velocity = move_and_slide(velocity, Vector2.UP)
if is_on_floor() and Input.is_action_just_pressed("ui_up"):
velocity.y = -JUMP_STRENGTH