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?

in Engine by (36 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

by (19,641 points)

Can you add all the code used Please? I am new to godot and cant seem to get something like this working (attracting enemies to player using point gravity.)

There is no code in this example. I only set the node properties as described.

Thanks, it's all good I figured it out.

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.