7ven Perks
7ven Perks

Reputation: 11

Godot body_entered detecting on start

I've been having an issue in godot 4.1.2 where when i start the game it detects the play entering the body 2 times, i found this out using

func _on_area_3d_body_entered(body):
     print("test")

how do i prevent this? im trying to use it for a level transition and its really messing things up

btw this is the area3d code:

extends Area3D

signal door


func _on_body_entered(body):
    if body is CharacterBody3D:
        door.emit()

So i then thought that maybe its because when you spawn in everything goes to one position but idk im very confused and its really messing things up

Upvotes: 0

Views: 754

Answers (4)

Sullivan Gray
Sullivan Gray

Reputation: 1

I had a similar problem. What you can do is add the player character into a group called player and then use a parameter to determine if the object entering the area.

if entering_body.is_in_group("player"):
    print("test")

Upvotes: 0

Charles Thomas
Charles Thomas

Reputation: 1

If you have a func _ready() Etc Etc Try deleting it it worked for me.

Upvotes: 0

Davidhdm
Davidhdm

Reputation: 81

Are your other objects CharacterBody3D aswell? If not then they should not trigger the "door" signal, but in the 1st method you posted it's normal if it's printing more than 1 result because you arent checking the type in it.

Also make sure you have set collision layers. When you make an Area2D/3D or an object that can collide, you usually want to give it a collision layer, and "scan" for other layers too, this is done by selecting the layers that you want that object to interact with, in the "Mask" part of the collision layers. With that, checking if it's a CharacterBody3D is unnecessary actually

For example if you have Player, Enemies and Coins, you probably want Player to interact with both the layers of Enemies and Coins, but the Enemies should only interact with the Player layer, to damage the player or whatever.

Upvotes: 0

7ven Perks
7ven Perks

Reputation: 11

Ok turns out that the issue is that for some reason its detecting the collision objects around it, not just the character which is odd

Upvotes: 0

Related Questions