Godot Version
4.2.1.stable
Question
I’m trying to use a PinJoint2D to connect two CharacterBody2Ds, but it doesn’t seem like Godot allows that. I can connect a CharacterBody2D to a RigidBody2D, I can connect a RigidBody2D to a StaticBody2D, I can connect two RigidBody2Ds, but I cannot figure out how to connect two CharacterBody2Ds, even though it should completely work as far as I know? A PinJoint2D just wants two physics bodies and a CharacterBody2D IS A PHYSICS BODY.
What I’m actually trying to do is have two CharacterBody2Ds get effected by gravity, but when I hold left click, I want the left CharacterBody to freeze and lock in place, then I want the same to happen to the right CharacterBody when I hold right click. Then I want both CharacterBodies to be pinned together so when one CharacterBody is locked in place, the other will swing like a pendulum, and the player can freely swap between locking the right and left CharacterBodies. As far as I know, both nodes that lock and freeze in place need to be CharacterBodies, because RigidBodies are weird when trying to freeze them (but if there is a way to properly freeze and unfreeze RigidBodies that I’m just missing, then that’d fix all my problems I think?)
What is happening right now is I have the two CharacterBodies and on scene start up they both just start falling (this is intended). I can hold left click to freeze the left body, I can hold right click to freeze the right body (this is also intended). But they are not tethered/pinned together at all. They act as if the PinJoint2D does not exist at all, even though I CAN SEE THE PIN IN GAME WITH DEBUG MODE AND THE TWO NODES ARE SET PROPERLY. Does the order of “node A” and “node B” for the PinJoint2D matter? Would I need to actively change each “node A/B” depening on which CharacterBody2D is frozen?
This is what my scene tree looks like:
My one PinJoint2D is connected to the “LHand” and “RHand” nodes. (LHand is node A)
The LHand script looks like this (the RHand script looks the same, but the input is looking for “grabR” instead of “grabL”.):
extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _process(delta):
velocity.y += gravity * delta
if Input.is_action_pressed("grabL"):
velocity = Vector2.ZERO
move_and_slide()
This is what the “Main” script looks like (the script attached to the uppermost node):
extends Node2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var LHand = $LHand
@onready var RHand = $RHand
@onready var PinJoint = $LHand/PinJoint2D
func _ready():
get_tree().paused = true
func _process(delta):
if Input.is_action_just_pressed("grabL") or Input.is_action_just_pressed("grabR"):
get_tree().paused = false
# left hand stuffs
if Input.is_action_just_pressed("grabL"):
PinJoint.reparent(LHand)
if Input.is_action_pressed("grabL"):
PinJoint.position = Vector2.ZERO
# right hand stuffs
if Input.is_action_just_pressed("grabR"):
PinJoint.reparent(RHand)
if Input.is_action_pressed("grabR"):
PinJoint.position = Vector2.ZERO
I hope that’s enough info? Thank you in advance!
(Is it usual to send the entire project file? Cause I don’t mind doing that if needed.)