Challenge

gdt_s03_physicsbody2d__making_a_character

#1

I used single line if statements to help with readability and used a direction variable to x axis movement. I also had a debug print() line in there to help confirm it was working correctly.
image


#2

Love your use of direction @bhindi1224 so I updated my code to use the same concept. I added some constants to enhance readability.

extends KinematicBody2D

# units are pixels for changing the location of objects on screen
const SPEED = 750
# movement directions
const LEFT = -1
const RIGHT = 1
const STILL = 0

# when the player moves this variable changes
var motion = Vector2()


# processes the physics engine every frame
func _physics_process(delta):
	# get input and set movement
	var direction = STILL
	if Input.is_action_pressed("ui_right"):
		direction += RIGHT
	if Input.is_action_pressed("ui_left"):
		direction += LEFT
	
	motion.x = SPEED * direction
	
	# apply movement to the player
	move_and_slide(motion)