0 votes

Strange topic description perhaps, I'll try and elaborate clearly:

I have a collision event in a script called ball.gd. It's attached to my ball.tscn file. Within ball.gd I have received the name of the body the ball has collided with. Like so:

var entity = ball.get_collider()

The entity is actually a brick, in my game of Breakout. It's an instanced scene of course. The brick has a variable built into it. The variable is called numOfHitsRequired

I've tried things like entity.numOfHitsRequired = x and other things but I just can't seem to set the variable. I want to reduce the numOfHitsRequired variable WITHIN the entity I've collided with so the brick.gd can handle itself as required. There are hundreds of bricks so I'm trying to deal with the one that's been identified in entity.

Any advice would be really appreciated.

EDIT: I've researched further and realised get_collider() returns the BODY that the item collided with. So that would explain why entity.numOfHitsRequired = x doesn't work. I'm still lost though. Just a little prod is all I will need I'm sure. Thanks again.

in Engine by (825 points)
edited by

1 Answer

+1 vote
Best answer

I just found it. For anyone in the future.

My scene was setup as:

- sprite
- StaticBody2D
-- CollisionShape2D

So I simply had to call entity.get_parent().numOfHitsRequired = x. It was the PARENT I had to call.

by (825 points)
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.