Godot Version
4.7
Question
Hi I’m trying to make a gravity similar to mario galaxy. Right now my player is just phasing right through. I have all my mask and layer set right.
class_name RelativeGravityArea2D
extends Area2D
func _ready() -> void:
set_physics_process(false)
func _physics_process(delta: float) -> void:
for body in get_overlapping_bodies():
body.up_direction = global_position.direction_to(body.global_position)
if get_overlapping_bodies().size() > 1:
set_physics_process(false)
func _on_body_entered(body: Node2D) -> void:
set_physics_process(false)
I presume you want to set physics process to true when entered
I set it to true yet I still clip through
it says
W 0:00:00:293 GDScript::reload: The parameter “body” is never used in the function “_on_body_entered()”. If this is intended, prefix it with an underscore: “_body”.
UNUSED_PARAMETER
relative_gravity_area_2d.gd:18 @ GDScript::reload()
Areas don’t stop collisions, only detect them. Do you need a StaticBody somewhere in addition to the area?
If i put a staticbody2d I thanI don’t stick to the platform
What is your “platform” now?
Maybe sharing a screenshot of your scene tree/editor would help
Your Area2D should be larger than the planet you want gravitational effect. The Area2D has properties for gravity overrides including “point” gravity towards the center of a planet.
The planet itself should use a StaticBody2D to stop the player from passing through it. You want both, an Area2D to affect gravity, and a StaticBody to stop other bodies.