#I always have problems with Area2D

1 messages · Page 1 of 1 (latest)

fierce scarab
#

You'll need to be more specific. What issues are you having, and how are you setting your collisions up? Remember that areas can report collision but they don't have a physical presence.

weary shuttle
#

Okay I guess I will make this a simple question. How to make collision detection with CharcterBody2D

#

@fierce scarab

fierce scarab
#

Did you add a collision shape to your characterbody2d?

weary shuttle
#

yep

#

@fierce scarab

fierce scarab
#

How are your collision layers set up?

weary shuttle
#

collision layers?

#

hells that?

fierce scarab
#

The collision layer is what your character sits on. Collision mask is what it recognises as an obstacle or interaction

calm berry
#

it would be easier if you follow a basic tutorial on setting up collisions

fierce scarab
#

If you have an object on a different layer, you need the corresponding mask or it won't detect it

past moth
#

@weary shuttle do you want me to make a video on it? Hopefully it can help

weary shuttle
#

yes please

past moth
weary shuttle
#

yep

#

am I even doing it right?

past moth
#

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

weary shuttle
#

okay what to do next? my mask and collision is on 1

past moth
#

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

weary shuttle
#

Jump_Boost

#

and can I make it so it detects if theres a tag on the jump_boost?

past moth
#

jump_boost sounds like an ability

weary shuttle
#

jump_pad

past moth
#

oh okay so when your character jumps on a jump_pad it flies up

#

that's what you're trying to achieve

#

?

weary shuttle
#

yep

past moth
#

Ahhh okay, 1 sec

#

what's currently on your script for your jump pad and your player?

weary shuttle
#
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 ?

past moth
weary shuttle
#

func _on_area_2d_body_entered(body):
if body.is_in_group("jump_boost"):
velocity.y = -600

#

That is the jump_pad script

past moth
#
   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

weary shuttle
#

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

past moth
#

so again

func _ready():
    add_to_group("jump_boost")

add this in your player

weary shuttle
#

did nothing. the player stands on the pad like nothing

#

Thats the player

past moth
#

whats in your jump_pad script then

weary shuttle
#

There isnt one

past moth
#

what

past moth
weary shuttle
#

yes

past moth
#

???

weary shuttle