|
|
|
|
Reply From: |
jgodfrey |
First, I assume your code looks like this instead of what you posted above?
get_tree().call_group("Block", "add_gravity")
If so, generally, that should work fine (and does work fine here, in a test project).
Here’s a screenshot of my working script and the scene tree. What’s different in your case?
sorry for the duplicate, must have clicked one too many times and Godot does not let me delete it.
And yes, the code looks similar and it does work when I set the gravity scale in the _ready part (be it by calling a group or by directly setting gravity_scale to 1).
What I am ultimately trying to do is to have a button in another scene that sends a signal and the receiver of that signal calls the group with the blocks and activates gravity.
So my full setup is
For the level scene:
Node (that I named ‘Level’)
- Button node with a signal connected to the node
and that Level node I have the following code:
func _on_Button_pressed():
get_tree().call_group("Block","add_gravity")
and then in another scene I have the block with the rigidbody, and on that rigidbody I have the following code:
func add_gravity():
print("gravity")
gravity_scale = 1
When the button is pressed, gravity is printed to the console, so I know the function triggers, and when I print the gravity_scale it is set to 1. But the object is not falling.
Sorry, should have explained the full thing straight from the start; I thought I could keep it a little more isolated. And thank you so much for the help!
1izNoob | 2020-03-14 19:28
So, after I more accurately replicated your setup (based on your most recent description), I saw the same issue you reported.
After some playing, I discovered my issue was that the RigidBody2D
was sleeping by the time I changed the gravity_scale
value (via a button press). And, while asleep, it doesn’t recognize the gravity_scale
change.
I was able to fix it here by unchecking the Can Sleep
property on the RigidBody2D
node in the inspector.
Hopefully, that’s your issue too.
jgodfrey | 2020-03-15 03:26
Yes, that fixed it! Thank you so much!
1izNoob | 2020-03-15 12:52