extends CharacterBody2D const SPEED = 300.0 const JUMP_VELOCITY = -400.0 @export var BUMP_FORCE = 90 # Shove attack @onready var right_ray: RayCast2D = $RightRay @onready var left_ray: RayCast2D = $LeftRay var faceleft = false var pushTarget var pushRightEnabled = false var pushLeftEnabled = false @export var PUSH_FORCE = 700 var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") func _physics_process(delta): if not is_on_floor(): velocity.y += gravity * delta if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = JUMP_VELOCITY # shove attack if Input.is_action_just_pressed("shove"): if pushRightEnabled && faceleft == false: pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 2) if pushLeftEnabled && faceleft: pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2) var direction = Input.get_axis("left", "right") if direction: velocity.x = direction * SPEED if direction<0: faceleft = true if direction>0: faceleft = false else: velocity.x = move_toward(velocity.x, 0, SPEED) move_and_slide() if right_ray.is_colliding(): if not faceleft: var collider = right_ray.get_collider() if collider is RigidBody2D: pushTarget = collider pushRightEnabled = true else: pushRightEnabled = false if left_ray.is_colliding(): if faceleft: var collider = left_ray.get_collider() if collider is RigidBody2D: pushTarget = collider pushLeftEnabled = true else: pushLeftEnabled = false for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_FORCE)