Godot Version
Replace this line with your Godot version
Question
Hello, i am trying to create a geometry dash like game in godot, but the only problem that I have is creating the script for the orbs, I am not that good in GDscript
Replace this line with your Godot version
Hello, i am trying to create a geometry dash like game in godot, but the only problem that I have is creating the script for the orbs, I am not that good in GDscript
You basicly have to check if the player is colliding with an orb to allow a jump mid air. I would suggest to use an Area2D
node as a child of your player to detect when an orb enteres/leaves the players area. The orbs will have an Area2D
as their range as well which has to be in a group called “orb”:
extends CharacterBody2D
@export var orb_detection_area : Area2D
const jump_height : int = 100
const gravity : float = 10
var level_velocity : int
func jump():
if is_on_floor() or is_touching_orb():
velocity.y = -sqrt(2 * gravity * jump_height)
func _physics_process(delta):
velocity.y += gravity * delta
if is_on_floor():
velocity.y = gravity
velocity.x = level_velocity
move_and_slide()
func is_touching_orb() -> bool:
if orb_detection_area.has_overlapping_areas():
return false
for area : Area2D in orb_detection_area.get_overlapping_areas():
if area.is_in_group("orb"):
return true
return false
Your hierarchy:
|--CharacterBody2D (player)
|--CollisionSHape2D (your players collider)
|--Area2D (orb_detection_area)
|--CollisionShape2D (use a CircleShape2D as shape)
|--Node2D (orb)
|--Area2D (orb's range, has to be in group "orb"!)
|--CollisionShape2D (use a CircleShape2D as shape)
|--Sprite2D (your orbs sprite)