PinJoint2D Problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bonkoponko

Hi everyone!

I’m working on a 2D physics-based space game and ran into some issues.

Basically I’m looking for a way to destroy my RigidBody2D-Spaceship on impact.
I tried a few things and ended up connecting the four rocket parts with 2x3 pinjoints which are deleted on impact. (1 is attached to 2 with two joints (to stop rotation), 2 is attached to 3, and so on)
Everything works fine until I start turning my rocket more than about 360 degrees…

All the forces are applied on the lowest part of the breakable rocket.
Steering code looks like this, pretty basic:

func _integrate_forces(state):
if alive and fuel > 0:	
		if Input.is_action_pressed("ui_up"):
		applied_force = thrust.rotated(rotation)
	else:
		applied_force = Vector2()
	var rotation_dir = 0
	if Input.is_action_pressed("ui_right"):
		rotation_dir += 1
	if Input.is_action_pressed("ui_left"):
		rotation_dir -= 1
	applied_torque = rotation_dir * torque

To have the rocket already exist of multiple parts seemed more straightforward to me than spawning the broken ship on impact and applying velocity and other forces on the individual parts. if you have another idea to implement a breaking ship I’d be happy to hear it :slight_smile:
Thanks guys!

Update:
I enabled collisions and put one pinjoint in the middle of the segments instead of two at the corners. look here

Seems to have fixed the issue.

bonkoponko | 2020-05-25 23:54