0 votes

What the title says.
I currently have this code:

extends Area2D

member variables here, example:

var a=2

var b="textvar"

var dumbile = false
func ready():
func collision
dumbile = true

func stenchian( bodyid, body, bodyshape, areashape ):
dumbile = true
func thisbetterwork():
dumbile = true
func _process(delta):
if(dumbile == false):

PS I have tried the same thing on the CollisionShape2D, to no avail.

in Engine by (28 points)
edited by

1 Answer

+1 vote
Best answer

It looks like you may have your nodes layered correctly and signals set up properly, but here's a rundown anyway:

Area2D needs a child CollisionShape2D in order to detect object collisions:
node heirarchy

Connect the body_enter and body_exit signals, either in the editor or via code:


In the body_enter and body_exit functions, set the object visibility accordingly:

func _on_Area2D_body_enter( body ):
    if body.has_method("show"): body.show()

func _on_Area2D_body_exit( body ):
    if body.has_method("hide"): body.hide()

Example project download: https://drive.google.com/file/d/0BwnfZQAEnciARS1idGN5cjZvZ3M/view?usp=sharing

by (1,314 points)
selected by

Comment for the PS: CollisionShape is just an editor helper (not an "real" active Node), it adds a shape resource on the parent, these can be added via code too (_shape methods).

So on what node would I put the script? The Area2D or the body it's colliding with?
PS When I add the CollisionShape2D to the node, it becomes visible as soon as the scene starts, I think this is because it's on top of a RigidBody2D, is there a way to ignore that RigidBody2D in particular or ignore all RigidBody2Ds?
PSS Nvm I found a workaround to that problem, this worked thanks for the help

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.