Can't seem to get `on_Node_body_entered(body)` working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By iamrifki

I’m trying to make it so that in my code if the Node Modifier gets its body entered, it will invert the variable numbers

extends RigidBody2D

export var speed = 250
var numbers = false

func _physics_process(delta):
    position += transform.x * speed * delta

func _process(delta):
    if numbers == false:
        $Label.text = "%"
    elif numbers == true:
        $Label.text = "7"

func _on_Modifier_body_entered(body):
    if body.is_in_group("shot"):
        numbers = not numbers
        print("SHOT")
    print("NOT SHOT")

It seems like _on_Modifier_body_entered doesn’t work at all as "NOT SHOT" and "SHOT" are never printed during testing.

enter image description here
enter image description here

No idea what’s happening, is there something wrong?

I closed the answer. to show as unanswered.

//////// Tried ///////
Get it right in “rigidbody properties”

from the inspector
contact_monitor = true

if it doesn’t work
////////////////////
try

func _on_Modifier_body_entered(body):
print(body)
pass
//////
The first one doesn’t work, and the second doesn’t print anything.

from the inspector

“Contacts Reported” to a value greater than 0.

////

Doesn’t work either, nothing is being printed.
///
Check that the signal is connected. The problem may be elsewhere.

ramazan | 2022-02-02 14:32

Seems connected
enter image description here

iamrifki | 2022-02-02 14:49

Also add a image of the “inspector” section.

ramazan | 2022-02-02 15:04

Here: enter image description here

iamrifki | 2022-02-02 15:06

I think you’re using this as a bullet. Add a wall across, will there be a collision with “Staticbody”?

ramazan | 2022-02-02 15:22

I’m doing this as a “bullet”, yes, but that’s not the point. There won’t be a staticbody collision. All I want to do is to trigger a function that inverts (truefalse and vice-versa) a variable from a signal.

iamrifki | 2022-02-02 15:30

:bust_in_silhouette: Reply From: umma

colliders can’t enter the rigidbody, it will just collide. my suggestion is to use an area node to detect when something enters collision zone. remember to disable collision layers for rigidbody wen doing this.

That worked, but it still displays a % instead of a 7

extends RigidBody2D

export var speed = 250
var numbers = false

func _physics_process(delta):
    position += transform.x * speed * delta

func _process(delta):
    if numbers == false:
        $Label.text = "%"
    if numbers == true:
        $Label.text = "7"

func _on_Area2D_area_entered(area):
    if area.is_in_group("shot"):
        numbers = not numbers
        print("SHOT")
        print(numbers)
    print("NOT SHOT")

iamrifki | 2022-02-03 00:57

Will probably make a new question for this, thanks for your help

iamrifki | 2022-02-03 06:47

try body entered also `func _on_Area2D_body_entered(body):
also what node is “shot”?

func _on_Area2D_body_entered(body):
if body.is_in_group("shot"):
    numbers = true
    print("SHOT")
    print(numbers)
print("NOT SHOT")

umma | 2022-02-03 06:47