0 votes

I'm trying to get two RigidBodies with Area node gravity to attract each other without issues. So far no matter how I set the area nodes, I either get one attracting the other, a standstill, or one or both vibrating/wobbling. I've tried messing with override, priority, gravity, mass, etc. to no avail.

I need to instance a bunch of these so I'd like to let the engine handle the physics if possible. Also, if possible, I'd like to have one of the RigidBodies be a controllable player.

Thoughts?

asked Aug 14 in Engine by spiderbyte87 (12 points)

1 Answer

0 votes

This should work pretty much "out of the box" without any code. I just tried it out and it works fine with this setup:

  • RigidBody2D

    • Sprite
    • CollisionShape2D (circle)
    • Area2D

      • CollisionShape2D (circle)

I set the global gravity to 0 in the Project Settings. I changed nothing on the RigidBody2D, except to set its linear/angular damp to 0, so the body won't experience drag.

On the Area2D I set the following:

Space Override: Combine
Gravity Point: On
Gravity Vec: (0, 0)

Adjust gravity strength and body mass as desired. Here's an example with two bodies, each with a random initial linear_velocity:

enter image description here

answered Aug 14 by kidscancode (10,848 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.