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).
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! I can’t figure out how that’d make a difference, but i’m gonna try anyway
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!
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!