Godot Version
4.3
Question
I am making an arcade style game similar to flappy bird but you have to steal bagels of incoming people. Right now I have 4 area2D collisions set-up for the player (Bad, Okay, Good, Perfect) for scoring purposes. Right now when I playtest it, it feels like the collisions are being detected below the visual colliders.
These colliders are connected to the player who has the basic physics movement Godot provides. Is there a physics component I need to add for the area2D colliders to be registering exactly what it is shown on the screen? Below is scripts:
Player Script:
extends CharacterBody2D
class_name Player
@export var speed = 300.0
@export var jumpForce = -400
var isFreeze: bool = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
if not isFreeze:
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("Jump"):
velocity.y = jumpForce
# Get the input direction and handle the movement/deceleration.
# Runner Direction & Movement.
var direction = 1
velocity.x = direction * speed
move_and_slide()
if isFreeze:
velocity.y = 0
Collect Script:
extends Area2D
@onready var game_manager: GameManager = %"Game Manager"
#Collision Bools
var isBad: bool = false
var isOkay: bool = false
var isGood: bool = false
var isPerfect: bool = false
func _process(delta: float) -> void:
if isBad:
game_manager.bad_score()
print("BAD")
queue_free()
isBad = false
if isOkay:
game_manager.okay_score()
print("OKAY")
queue_free()
isOkay = false
if isGood:
game_manager.good_score()
print("GOOD")
queue_free()
isGood = false
if isPerfect:
game_manager.perfect_score()
print("PERFECT")
queue_free()
isPerfect = false
func _on_area_entered(area: Area2D) -> void:
if area.is_in_group("Bad"):
if Input.is_action_just_pressed("Jump"):
isBad = true
if area.is_in_group("Okay"):
if Input.is_action_just_pressed("Jump"):
isOkay = true
if area.is_in_group("Good"):
if Input.is_action_just_pressed("Jump"):
isGood = true
if area.is_in_group("Perfect"):
if Input.is_action_just_pressed("Jump"):
isPerfect = true
func _on_area_exited(area: Area2D) -> void:
if area.is_in_group("Bad"):
if Input.is_action_just_pressed("Jump"):
isBad = false
if area.is_in_group("Okay"):
if Input.is_action_just_pressed("Jump"):
isOkay = false
if area.is_in_group("Good"):
if Input.is_action_just_pressed("Jump"):
isGood = false
if area.is_in_group("Perfect"):
if Input.is_action_just_pressed("Jump"):
isPerfect = false