#The Right Node for the Job - Area2D vs RigidBody2D, or both?!

1 messages · Page 1 of 1 (latest)

loud swallow
#

I'm having a problem understanding which nodes to use for collision detection /overlap detection and physical contact.

I want to build an object, let's call it a Slider.

I want the Slider to "bounce" back and forth from left to right. This seems good for a RigidBody2D? The Slider can bounce between two "wall" objects, that are also RigidBod2Ds themselves?

And then I also want this Slider to detect overlaps, so that if it's over a particular object, when the player hits a button during overlap, something can happen. This seems perfect for an Area2D? Using get_overlapping_areas() yeah?

The issue I seem to see is that an Area2D does not have the robust collision / contact detection that a RigidBody2D does, yet at the same time detecting various states of "overlapping" between objects with a RigidBody2D is not what it seems built for?

Do I need a combination of both in a single object? Or can I achieve both with a single type? Is there a way to detect overlaps with a RigidBody2D that I am not understanding? It makes sense of course the more I think about it, that maybe the RigidBod2D node isn't designed for objects that are at all expected to go inside each other?

sick valley
#

Both.

loud swallow
#

So sanity check on something like this?

  • Slider -- RigidBody2D for bounce, and Area2D for overlap detection
  • Zone (what gets overlapped on) -- Area2D only for interacting with the Area2D on the slider when it passes over

In the image:

  • Blue box: Slider
  • Green boxes: Boxes the slider overlaps over