[kind of solved] Joining two mobile objects causes weird rotation

I am still working on my physics based space game and ran into a problem that’s been boiling my head for too long now, i could use some advice:
The player is controlling a small spaceship in an environment with multiple gravity sources (aka. space, haha). Now the thing is that i want this spaceship to be able to hook up to and tow away objects to bring them to “the base”.
I worked with a Point2PointJoint between the ship and the object plus a visual representation of the joint like a glowing ray. Everything works fine except that joining the objects makes my ship spin around for no obvious reason in 50% of the cases. When i remove the joint (unhook the ship), this rotation is still present. If i rotate the ship to steer it, it seems to overwrite the unwanted rotation, but as soon as i stop pressing the steering key, it spins around again.
I tried playing around with the settings of the joint - but no success.

I hope this is not too abstract. I basically want to make something like this, but with multiple planets/gravities. If you want to try the WIP project to understand the problem, here’s the repo: https://github.com/bkis/OreBit.git
Arrows to steer, space (hold) to hook the grabbable object (red sphere). The cyan colored box represents the ship for now (which sucks because you can’t see where the front is).

Thanks in advance for your suggestions!

I just looked up what “point to point joint” means, and I am no expert on this, but this is the picture I got:

So, this doesn’t look exactly like a grappling hook to me, because you expect to pull the object toward you and I don’t think this type of joint supports that.

No i know how this joint works. if you hit the key, there will appear a link between the ship and the object. The distance will stay the same… no pulling. The object then “swings around” on that connection, like on a stiff rope or something.
So this is what i want.
But are joints meant to always have one fixed node maybe? In my case, both are mobile/dynamic. Maybe that’s causing the problem?
Can anyone think of a way?
Thanks again!

Perhaps you do not want to attach the joint to the ship, but instead attach it to a fixed body which follows the ship?

Thanks! I can’t figure out how that’d make a difference, but i’m gonna try anyway :smile:
If it doesn’t work i might try to write a control which does the job “manually” - maybe these joints are really not meant connect two moving objects… I’ll report back, thanks for now!

Ok… it turns out using a physics joint for that purpose was “mit Kanonen auf Spatzen geschossen”, how we say in Germany (like “using a sledgehammer to crack a nut”).
Now i just check the distance between my ship and the object and keep it fixed to the initial distance they had when the connection was made. Simply with a control. It works fine for that purpose and isn’t as costly as a physics joint.
Thanks for your input anyway!

Make sure you set your following object to kinematic mode if you directly set its location and rotation, otherwise you might get funny collision behavior.

Thanks for the hint! But it’s important to have the following object affected by gravity, too. You know, it’s supposed to act like a load the ship has to carry. Like a helicopter carrying something heavy on a rope, it should swing around according to the gravitational forces it’s affected by.
So now i move it by applying forces in the direction of the ship and keep it dynamic. If there are any downsides to this approach which i don’t see, I’d be happy if you pointed them out! Thanks!

FYI: you’ve implemented a spring, effectively. Which should be fine.

Well, I didn’t look at it this way, but now that you say it: When I set the parameters of my implementation right, it actually behaves like a spring, right! :wink:

Applying forces is fine, just setting position and/or rotation would cause issues (its like the object is “beaming” instead of moving for the physics system).