Now, I would like to achieve the following: when the player runs on the beam, I want the scale to tilt accordingly. I have already used Area2D to detect when the body is on it, but how can I exert force on the beam?
Here is the test code I cobbled together from the internet, but it doesn’t work properly. The scale only tilts to one side, and walking on it has no effect. The only thing that works in the code is that the scale realigns itself when the player steps off.
extends RigidBody2D
@export var return_speed = 6.0
@export var player_weight = 80.0
@export var gravity = 980.0
var players_on_scale = []
func _physics_process(delta):
angular_velocity += (-rotation * return_speed) * delta
for player in players_on_scale:
var force = Vector2.DOWN * player_weight * gravity
apply_central_force(-force)
func _on_area_2d_body_entered(body: Node2D) -> void:
if body.is_in_group("Player"):
players_on_scale.append(body)
func _on_area_2d_body_exited(body: Node2D) -> void:
if body.is_in_group("Player"):
players_on_scale.erase(body)
Can anyone help? I’m feeling a bit overwhelmed at the moment.