Godot Version
godot 4.7.2.stable
Question
I want my player to flip and move the opposite way when the raycast detects a certain collision like maybe that has a group or something
extends CharacterBody2D
@onready var raycast = $RayCast2D
const FLAP_POWER = -300.0
const MOVE_SPEED = 180.0
var flipped = false
func _onready():
flipped = false
func _process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("Flap") and not is_on_floor():
velocity.y = FLAP_POWER
if flipped == false:
velocity.x = MOVE_SPEED
elif flipped == true:
velocity.x = -MOVE_SPEED
if raycast.is_colliding() and flipped == false:
flipped = true
elif raycast.is_colliding() and flipped == true:
flipped = false
move_and_slide()