PinJoint2D - angular limits don't work?

Godot Version

4.2

Question

Is anyone able to get the angular limits to work on PinJoint2D nodes? I can’t for the life of me seem to get them to have any effect (have checked “Enabled”, still nothing).

Thanks very much.

1 Like

I’m having the same issue, it only rotates freely, can’t stop or limit it.

Thanks Ozzy, good to know it’s not just me.

I’ll have a play around sometime in the next few weeks and try and come up with a reasonable workaround. I’ll let you know if I get anywhere, grateful if you let me know if you figure anything out too!

Heyo, same problem for me. I tried a few things with the motor of the PinJoint2D and the actual angular velocity of the rotating node.
These different ideas vary from the circumstance they are used in.

This script connects directly to the PinJoint2D.

I hope the comments and variable names aren’t too confusing (me newbie :grimacing: )
You may juggle a bit with the numbers, so you hopefully find the right ones for your application.

Hope it helps <3

extends PinJoint2D

@export var limit_cgw: int = -45 #limit in counterglockwise direction
@export var limit_gw: int = 45 #limit in glockwise direction
#@export var motor_speed: int = 50 #how fast the motor corrects the rotation
@export var control_node: Node2D  #literally Node_B

#func _ready():
	#motor_enabled = true
	#motor_target_velocity = 0

func _process(delta):	
	
	#--------Probably my best take-----
	
	if control_node.rotation_degrees < limit_cgw:
		control_node.angular_velocity = 1
	if control_node.rotation_degrees > limit_gw:
		control_node.angular_velocity = -1
	else:
		pass
		
		
	
	
	#--------Can't stand heavy impacts, but adjusts softly (uncomment var motor_speed at the top and the ready func)---------
	
	#if control_node.rotation_degrees < limit_cgw:
		#control_node.angular_damp = 100
		#motor_target_velocity = motor_speed
	#if control_node.rotation_degrees > limit_gw:
		#control_node.angular_damp = 100
		#motor_target_velocity = - motor_speed
	#else:
		#control_node.angular_damp = 0
		#motor_target_velocity = 0	
	
	
	#-------Tried to combine the previous ideas-------
	
	#if control_node.rotation_degrees < limit_cgw:
		#control_node.angular_velocity = 0
		#motor_target_velocity = motor_speed
	#if control_node.rotation_degrees > limit_gw:
		#control_node.angular_velocity = 0
		#motor_target_velocity = - motor_speed
	#else:
		#motor_target_velocity = 0

Thanks for that Minkwumpf! That looks like a good idea.

I think your aim might differ slightly to mine. I’m looking to do a hard stop between two rigid bodies aren’t allowed to rotate at all past the angular limits (trying to do an elbow joint) but also keep all the other physics working (I’m applying torque to the nodes connected to the pin joint).

I’m wondering for my case if just adding another node (invisible, in its own collision layer) to act as a physical blocker to stop one part rotating further might be the easiest way to keep all the other physics working.

An own “blocking collision layer” sounds interesting.

I actually aimed for an elbow joint too, but i guess i need to come back to this quest when my knowledge level is higher. :grin:

But i will come back stronger! Or atleast to look how people solved this issue.

Good luck and much success!

Good luck to you too! I’ll let you know if I figure anything out :slight_smile:

Just to let anyone who comes across this know, if you use Box2D for Physics instead of Godot Physics, the angular limits work!

1 Like