Godot Version
4.4
Question
I want to create a plank-like physics object that can rotate based on the player’s weight when standing on it. like in the image below. How can I possibly achieve this? I started using RigidBody and played around with the settings. I even used pinjoint2D, but nothing seems to give the plank any movement like a plank that swings by weight. One thing that is working is giving the angular damp values, but it is still moving on its own. It’s not waiting or affected by player weight. Any suggestions?
Assuming your player is a CharacterBody:
By default, CharacterBodies don’t push RigidBodies. So you would have to manually implement that via code, which is usually something like this:
# in you player's script
var weight := 200.0
func _physics_process(delta: float) -> void:
# ...
move_and_slide()
for i in get_slide_collision_count():
var collision = get_slide_collision(i)
var collider = collision.get_collider()
if collider is RigidBody2D:
collider.apply_force( -collision.get_normal() * weight, collision.get_position() )
For creating the actual plank, using a pinjoint to attach the RigidBody to a StaticBody should work then.
I managed to solve my problem by removing all this unnecessary code. I added a RigidBody2D to my player’s feet, and to my platform, I added a StaticBody with a smaller collision shape. They both connected to a PinJoint2D. This was much simpler and had no code usage at all. thanks anyway