I'm sorry clark, I tend to get carried away with my own ideas.
My original intention was that you replace the distance joints, with the "bounded" revolute joints. Though now you mention it, you could use two overlaid joints for the same effect... ah, i'm going off again. There are a lot of ways to tie things together in Box2D with joints, with only subtly different results.
However, on re-consideration, you actually have several different problems, and you might find it easier to break it down into separate steps. I suggest you put ALL your shapes into one body, which makes them perfectly rigid. No joints whatsoever.
With this considerably simpler setup, you can experiment more easily with different methods of propulsion and control, and perhaps see for yourself how rotation works in practice. Words have evidently failed me.
Then when you are happy with that, you can consider going back to the joints approach discussed here, which is really an advanced technique so that your space ship wobbles from impacts, etc. You then have a base case to compare the joints situation to, so you can tell when it's working properly, and you can do it a couple of joints at a time.
Not at all boris, your ideas are welcoming.
I think you just hit the nail on the head. in that what i am trying to do is advanced... well more advanced than my stage. Thats all i needed to hear as i thought what i had chosen to do would be a simple excercise and hence why i spent so long attempting a solution.
I am still not done with this but for now ill take your advice and lay it to rest and stick with the shapes inside a body approach. However, things like breakable bodies and moving multiple bodies in this way are what i see when i visualise any type of game using the engine and i dare say ill be back again soon!
Thanks for all your help lads.
I'll start to model my spaceship for my game soon, and I also wanted my ship to be a little less than completely indestructable. One of my ideas that I am planning on experimenting with, is to create the ship as a fairly complex polygon shape, and to modify its actual shape when there are big enough collisions. This is no doubt going to be very complicated so I may very well abandon it or settle for some other method/effect... I definitely want my ship to have some type of interaction with the environment that goes beyond pure rigid body dynamics though, so stay tuned...
Yeah dc it adds character what you may try to create sounds much more complex than mine!
A new day and a new question tho! 😀
The following diagram speaks for itself. At the bottom is what i ended up with before bed lastnight, (i couldnt stick to 1 body and i have no idea why im obsessed). It works but its pretty much a hack job. If this is the best way forward, im sure i could rig up bodies like this so when the ship lands badly itll break apart by distroying relavant joints. I was intregued by the mouse joint tho.
I look forward to seeing your future attemps dc.
Using distance joints might work out well but also might not, depending on how stable it is. It seems like that structure of yours would tend to "explode" or get mangled up, and it would be hard to get the feet back where they're supposed to be.
What you might want to try is to set up a spring force that pushes each landing pad to a relative position on the main body, and also apply the opposite force to the main body itself. This will generate a physically correct spring.
The vector math involved isn't terribly complicated but you'd definitely want to get a good grasp of how vectors work.
The direction that you'd want the (I'll call it a wheel because this is also great for vehicle suspensions - though for a more realistic vehicle suspension i'd use a prismatic joint along with it, but that's not the point) wheel to have a force applied towards where it *should* be, which is, say, -10,-5 in local coordinates on your main ship body.
Box2D has some very very useful helper functions such as GetWorldPoint(), where you can just say ShipBody->getWorldPoint(vector(-10,-5)) and that will return the target position of your wheel. What you want to get a spring force is to make a force going from the current position of the wheel to the target position, and have the force magnitude proportional to the *distance* of this displacement. This is because a spring force is proportional to displacement as you may know from hooke's law.
soo the force vector should be: constant * (target - currentPosition) [note that target and currentposition are both vector quantities.. just take your vectors and subtract them] and apply it to the center of mass of the wheel, and remember that target is ShipBody->getWorldPoint(vector(-10,-5)), and the constant can be any scalar value you want, it determines the stiffness of the spring.
Now all thats left is you must apply the exact same force in the opposite direction, on the ship body itself. (Newtons second law) You apply it on the position that the wheel should be, i.e. local coordinates -10,-5. This way you can push and torque the body by moving the wheel. If you neglect to do this part you'll see what happens when you run it. It would violate conservation of energy, yadda yadda.
Couple little things: when applying the force, you can do either applyImpulse or applyForce, but they will differ by a factor of physics timestep. I would recommend applyForce.
Also you would definitely want some damping on the spring forces because if you follwoed my directions you'd get a "perfect" spring, which though nice will continue to oscillate and vibrate, which is cool but also kinda stupid looking and could get annoying as well. I forget the correct way to do it, but you can just multiply each force applied by a constant lower than one, such as 0.97. then energy will be lost slowly like it does in reality.
So that's about it.. hope that helped.
Excellent post dc and much appreciated.
Im going to follow the post this afternoon and see what i can come up with and the references you make will provide me with decent search terms on google.
Ill post what i come up with when im done.
Hi,
I have seen another implementation
in each timestep
spring1->SetMaxMotorForce( baseSpringForce + (40 * baseSpringForce * powf(spring1->GetJointTranslation(), 2) ) );
spring1->SetMotorSpeed( -20 * spring1->GetJointTranslation() );
spring2->SetMaxMotorForce( baseSpringForce + (40 * baseSpringForce * powf(spring2->GetJointTranslation(), 2) ) );
spring2->SetMotorSpeed( -20 * spring2->GetJointTranslation());
Where baseSpringForce is 5 times the mass being supported by the spring (i.e. the car in this example).
I am not sure what the physics behind this is, but it seems to involve the distance of the joint translation squared as a factor, and then seems to set the motor speed in the opposite direction to the prismatic joint translation.
WHat is the physics this is based on, what are the constants? Which is the correct implementation of a prismatic spring for, for example, wheel suspension??
So many questions, so little knowledge!!
Thanks
i