0 votes

So here is the scenario.

I have a space sim, and I'll have several overlapping Area2D:

  1. The Sun's sphere of influence (SOI)
  2. A planet's SOI
  3. A planet's Atmosphere

I will have many objects that can interact with these gravity fields, but I want them to be able to do some orbital calculations as well.

In order to do these calculations I need to know the objects position, the objects velocity relative to the area2d centroid, and the gravity present in the area2d as well as the gravitydistancescale.

I also need to be able to tell if the area is an Atmosphere or a gravity well.

I need to do this in priority order.

So the trick is, I need the bodies to track the area2d they are inside.

The signals that Area2D provides aren't enough. I can get body_entered but this does not pass the Area2D to the body for me to keep track of. It also doesn't give me the first Area2d I start in onready.

Any advice for listing objects of a certain type in the scene or some other way to do this?

in Engine by (17 points)

1 Answer

0 votes

Hi,
put the areas into groups. Get them with getTree().getnodesingroup ( String group )

or

You can use body_entered:
connect the signal to the area itself ... then ...

connect("body_entered",self,"_on_body_entered")

func _on_body_entered( node ):
    node.i_just_entered_this_area( self )
by (2,940 points)

Good suggestions, thanks!

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.