I am making a physics based tank game, I need to keep the tracks (made up of many individual links, each with a Joint
and a Rigidbody
) on the guide wheels, I don't really know the best way of doing this, I want the game to be as physics based as possible but I don't want to simulate a pointlessly high level of detail (want to avoid mesh colliders as much as possible). It should be fine to constrain the links to a plane defined by the guide wheels, but I can't see a good way to do this. Any suggestions are apricated as to how I could achieve the desired affect, please keep in mind that the links use box colliders.
CodePudding user response:
For maximum performance, I suggest implementing your own iterative solver. I did so a few years ago for keeping a (rather unimportant detail) toy train on its tracks. I would fake effects like gravity and tension. This way, you stay in control and you can design the most crucial part of your game to behave like you want it to. Physical interaction can be simulated by many small invisible wheel colliders or by directly exerting forces on the environment.
The iterative solver algorithm has a leading link, which moves a given distance on a piecewise-linear path. Then iteratively solve for the position of the second link, where you want the distance of their connection point to be as close to zero as possible while finding the correct position on the path. Just a matter of finding the zero of a cheap-to-evaluate black box function. Rinse and repeat until you have the position of the last link (which needs to solve for two connector points). You can make this really fast (if needed) by estimating initial guesses and so on. Effects like gravity can be achieved by introducing or relaxing constraints.
CodePudding user response:
I have realised this is possible with configurable joints. Since spacial contraints are defined in local space, it should be possible to get the desired effect without too much difficulty.