class_name Player extends CharacterBody2D @onready var rightcast: RayCast2D = $rightcast @onready var leftcast: RayCast2D = $leftcast const SPEED =200.0 const JUMP_VELOCITY = -300.0 var direction enum FaceDirection{LEFT, RIGHT} var facing:FaceDirection = FaceDirection func _physics_process(delta: float) -> void: handle_input() handle_movement(delta) move_and_slide() handle_collisions() func handle_input()->void: if Input.is_action_just_pressed("ui_accept"): velocity.y = JUMP_VELOCITY if Input.is_action_just_pressed("magic push"): print ("may the force be with you") # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. direction = Input.get_axis("ui_left", "ui_right") if direction<0: facing = FaceDirection.LEFT if direction>0: facing = FaceDirection.RIGHT func handle_movement(delta)->void: if not is_on_floor(): velocity += get_gravity() * delta # Handle jump. velocity.x = direction * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED) func handle_collisions()->void: if rightcast.is_colliding() and facing==FaceDirection.RIGHT: print("yay") move_and_slide() for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: #deliver the impact c.get_collider().apply_central_impulse(-c.get_normal() * 100)