Hi! I'm trying to create a prototype 2D physics based game. (like Hill Climb Racing). I'm newbie so I have a problem. I was created two wheels: and a 'transmission': And added to sprites colliders rigibodies. And for first wheel i added two spring joints (first SJ connected wheels, second connected wheel and transmission), for second i added one spring joint. So I have something like this: On a flat surface all good, but this is what happening on an inclined surface: What I'm doing wrong?
I tried doing what you did and got really strange results as well. Its kinda a bad solution, but you could try using both spring and slider joints to connect the tires to the body. like this: Where you have two spring joints on the body, which connect to the wheels, then one slider joint on the body to one wheel, and another on the other wheel, connecting to body (only because you cant have two slider joint components on one gameobject) this creates a semi-realistic suspension.... sorta haha EDIT oh another thing you must match up the numbers for the anchor points or things will go really crazy trying to fight between the joints... so if anchor of rear wheel on spring joint is x, y, then anchor of rear wheels slider must also be x, y... make sure they match or it will create strange results this way as well. So that means if you have two spring/slider joints on your body, which have anchor of -5 and -10 connecting to the rear wheel... then also on the rear wheel you have just a slider connecting to the body, the anchor must be POSITIVE 5 and POSITIVE 10, which matches up the locations of the joints... get it? it would be opposite because its below the body, making all the joints trying to hold all the parts in the same position, sliders allow only one axis of movement, and springs allow the... springyness
I solved the problem. It's just trigonometry. Physics does not help here. At first we must deduct X-coordinate first wheel from X-coordinates second wheel. And so the same we must deduct Y-coordinate first wheel from Y-coordinates second wheel. And then calculate atan2 degrees. And always rotated the transmission by that amount. Maybe it will help someone.