#I always have problems with Area2D
1 messages · Page 1 of 1 (latest)
Okay I guess I will make this a simple question. How to make collision detection with CharcterBody2D
@fierce scarab
Did you add a collision shape to your characterbody2d?
How are your collision layers set up?
The collision layer is what your character sits on. Collision mask is what it recognises as an obstacle or interaction
it would be easier if you follow a basic tutorial on setting up collisions
If you have an object on a different layer, you need the corresponding mask or it won't detect it
@weary shuttle do you want me to make a video on it? Hopefully it can help
yes please
are you using godot 4.3?
yeah, but you may need a couple things in addition to that, on the right you'll see the 'inspector' tab, look under that and expand the collision
for example, i left my layer / mask on 1
okay what to do next? my mask and collision is on 1
perfect, now what are you trying to collide it with? are you trying to take damage from an enemy?
Collision LAYER: where an object exists in the world
Collision MASK: what the object should collide with
jump_boost sounds like an ability
jump_pad
oh okay so when your character jumps on a jump_pad it flies up
that's what you're trying to achieve
?
yep
extends CharacterBody2D
@export var speed = 300
@export var gravity = 30
@export var jump_force = 300
func _physics_process(_delta):
if !is_on_floor():
velocity.y += gravity
if velocity.y > 1000:
velocity.y = 1000
if Input.is_action_just_pressed("Jump") && is_on_floor():
velocity.y = -jump_force
var horizontal_direction = Input.get_axis("Left", "Right")
velocity.x = speed * horizontal_direction
move_and_slide()
func _on_area_2d_body_entered(body):
if body.is_in_group("jump_boost"):
velocity.y = -600
I know it says jump boost but just think of it as jump_pad
@past moth ?
and what's on your jump_pad script
func _on_area_2d_body_entered(body):
if body.is_in_group("jump_boost"):
velocity.y = -600
That is the jump_pad script
if body.is_in_group("jump_boost"):
body.velocity.y = -600
in your player add this
func _ready():
add_to_group("jump_boost")
try it and let me know
also chatGPT coding is a bit outdated
yea I think you miss-understood. the
func _on_area_2d_body_entered(body):
the "body" is the Jump-Pad
so basically the player detects it
so again
func _ready():
add_to_group("jump_boost")
add this in your player
whats in your jump_pad script then
There isnt one
what
you said this is the jump_pad script lol
yes
???
The player sees if they touched a object with the tag "Jump_Boost"