Is there a way to make a RigidBody2d magnetic?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MIna

I need a rigidbody2d with a sphere collision shape to magnetically attach to instances of itself when they get into a certain proximity of each other. Any tips or links to tutorials?

:bust_in_silhouette: Reply From: Nathuunn

Maybe you could use an Area and when a object enters the Area then use the move_toward() function. Im still pretty new to godot so idk if this would work

so position.move_toward(Vector2(x, y), speed)

Interesting, I’ll try it out, thank you.

MIna | 2020-09-05 02:41

:bust_in_silhouette: Reply From: bingbong

Sounds a bit like the ‘planet jumper’ tutorial I have been trying to pick apart this last week might be along the lines you are looking for…

I’m checking it out, thanks.

MIna | 2020-09-04 23:05

:bust_in_silhouette: Reply From: maxwellc055

Hey!

Some fun stuff I read about today.
One of the many benefits to Area2Ds is their ability to alter physics. One of these alterations is known as point gravity. I can see you using an Area2D node as a child of your RigidBody2D node to achieve the desired effect. More details about this process can be found towards the bottom of this page.

I hope I could be of some assistance to you.
Maxwell

Hi,

I was trying Area2D’s gravity point before but I didn’t realize I had a bug with the gravity:
RigidBody2D mass/weight broken? - Archive - Godot Forum

I ended up starting a new project and recreating my scenes and it works just fine now.

Thank you.

MIna | 2020-09-12 17:28

So glad you got it figured out!

maxwellc055 | 2020-09-12 18:16