Hockey stick sometimes fails to shoot properly

Godot Version

4.3

The issue

I’m working on a 2-player game, it’s essentially ice hockey but in 2D. The hockey stick and the hockey puck are both Rigidbody2D nodes. The hockey stick’s global position is constantly set to the player’s to prevent it from falling down. The stick changes direction by changing the angular_velocity property.
Most of the times the stick succesfully shoots the ball, however certain times the puck doesn’t move well . It also glitches inside walls.

Link to the video showing the bugs
When I observed the video frame by frame, I noticed that the hockey stick pushes the puck down instead of up, that causes the ball to not be shot properly. However I don’t know how to solve this issue neither.

Ball rigidbody properties:

Hockey stick rigidbody properties:

Part of the hockey stick script that applies forces

func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
	var dirs = [[-90, -40], [-45, 30]]
	if hstate != oldstate:
			tick = 0
	global_position = get_parent().global_position
	if hstate == hockeyState.prepare:
		state.angular_velocity = 0
		rotation = deg_to_rad(dirs[player-1][0])
		state.angular_velocity = -30 * sens
		hstate = hockeyState.ready
		
	elif hstate == hockeyState.shoot:
		if tick == 0:
			state.angular_velocity = 50 * sens
		elif rad_to_deg(rotation) > dirs[player-1][1] and tick > 0.05:
			hstate = hockeyState.retake
			
	elif hstate == hockeyState.retake:
		if tick > 0.55:
			if state.angular_velocity > -50:
				state.angular_velocity = -10 * sens
				
			if rad_to_deg(rotation) <= dirs[player-1][0]:
				hstate = hockeyState.idle
				state.angular_velocity = 0
				rotation = deg_to_rad(dirs[player-1][0])

Could you try using a PinJoint2D instead of setting the global position? I imagine that is a large portion of the problems

The hockey stick now doesn’t fall from the player, but it now rotates kinda wherever it wants to. I set the stick’s gravity to 0 and the problem still persists. Also the player jumps a bit when you fire and the ball goes away when the hockey stick didn’t even touch the ball. I commented out the global_position line. The overall collision behaves much weirder.


I also recently discovered this weird bug where there is a delay between the hockey stick hitting the puck and the response.

bump bump