A list of questions after reading the manual.

Hey people,

I spent 12 hours yesterday writing down the manual and looking up terms and things like that.

Anyway i have some questions regarding the engines usage.

How can i control a group of objects? For example, i created 5 circle bodys and connected them with distance joints to give me the shape of a space ship with suspension. When i apply an impulse to the centre particle of this structure, it takes flight which is good news.

However, i have no idea how to work with rotations. If you think of lunar lander or asteroids, you can control the rotation of the craft and then pressing "thrust" will thrust your ship in the direction its facing. Well this is killing me in both box2d and previously APE.

It would seem logical that is the user presses right or left, i could rotate SOMETHING by x radians. When the user presses up, i could get the rotation of SOMETHING and try to apply impulse alone the ships rotation.

As you can see, even if i am on the right track, i dont see how SOMETHING can be anything other than the structure as a whole and this is what is confusing me. Is there a better approach to this problem? I understand i could create 5 shapes instead and add them to a single body and then control that body but then i wouldnt be able to connect the shapes together using joints to create suspension. Id have a rigid shape shaped like a spacecraft?

What i would do in APE would be to extend the Group or Composite classes to group particles together and i cant seem to break out of this mindset.

Any advice would be great.

Thanks 😀

(2.0.1)
Sounds like you need to do some math and apply a rotation to all the body parts individually. It's late at night, and I haven't used Box2D for awhile, but if you could somehow set the origin of each of the parts to the center of the overall structure and then rotate each point around that, it should work no? I don't recall if box2d has any method for changing the origin of the body parts to rotate around, but if not... well you'll just have to calculate the appropriate forces yourself.
Thanks for the reply dude.

Certainly ill look into what you say but have attached a diagram to get across the idea better. Certainly ill need to look at origins or work out how to set the bodies position with maths but just wondering if theres any other ideas out there before i comit to a week of studying lol.

Cheers!

EDIT: viewtopic.php?f=8&t=358&hilit=rotation
You are holding the ship together with distance joints, and they are presumably attached to the center of each circle. In that setup, each circle is free to rotate in place relative to the ship. This is no doubt what is causing your confusion about rotation, as your individual circles are not rotating, and it is relative to shapes that most of the Box2D API works.

Instead you want the circles to be completely rigid with respect to each other. This is usually achieved by replacing the distance joints with revolute joints which have the min and max angle set to the same value. This may not look as convincing once you make them soft joints, if revolute joints work as soft ones at all (I am assuming you are aiming for soft joints that or else you would have just put all 5 shapes in one body).

Having ensured that the circles rotate with the chasis, you can then use the ApplyForce function on that middle circle, using GetWorldVector to get the appropriate direction for the force. You could also use ApplyTorque to steer the ship, something that wouldn't currently work as the individual circles would just spin on their own.

Without the circles rotation, doing some maths would be unavoidable to calculate the ships rotation from the relative position of the circles. (though it wouldn't be as hard as you assume. In fact, all that is necessary is to subtract the position of the top circle from the position of the middle circle, and that gives you the direction the thrust should be in. In fact, having written this it may be well be the easier solution, if you don't think the rotation of individual components will cause you problems).
Hey Boris!

Thanks for your reply dude!

I am picking up on some of what you are saying. After reading the box2d manual yesterday, today i went through the 2.0.1 API found here:

http://linuxuser.at/elements/doc/box2d/classes.htm

And checked out what methods and properties are avilable to all the classes and what they do. I can see some light now, on Sunday night i didnt have a clue so im making some progress!

I think the next stage is to move on to explainations of visualising concepts i have never seen before, i understand friction for example and what that means, restitution means bounce... the childish comparisons are the staple to my learning process. You touched on getWorldVector() and one of my previous notes was to find out what the difference between getWorldVector and getWorldPoint (i think) was.

Once i understand a bit more of such functionality, i will return to your reply to make better sense of it, terms like linear velocity and angular velocity right now are mere stabs in the dark in my understanding.

Ill be back in a couple of days.

Cheers.
Wikipedia articles on some of those physics terms may prove to be very helpful.

good luck!
Boris i had another look at what you said but im still stumped.

Everything i think of that is interesting seems to be done with multiple bodies but this is stumping all my efforts. No matter what i do i cant grasp moving objects relative to eachother.

I think i need more help!
If I were trying to make a spaceship with a soft-suspension-equipped landing gear, I would make a main ship body and attach two or more "legs" with prismatic joints, and then attach "feet" to the "legs" using revolute joints with some limits (so they dont spin around full circle). I would then look into how to do the suspension, if the box2d motors arent enough to simulate the friction/damping/spring effect. Probably just giving the prismatic joints a motor force pushing down with a reasonable max force should work decent enough.

This way, your landing gear is ATTACHED to your ship and you wont need to worry about it wobbling out of control or being oriented anywhere other than where it's supposed to be (i.e. the bottom of the ship..)

A simple damped spring is really easy to do, afaict (take the spring force and multiply it by a constant smaller than 1 before applying it).
Thanks for the reply man im still trying!

I tried to do what i think you mean,create a body and then another 2 bodies as "feet" and connected them all up with soft distance joints... A triangle (you said prismatic.. does it matter?).

Im confused with the rotation still though. As far as i understand, i have 3 bodies and 3 joints connecting each of them. I dont see where there is room to add revolute joints with upper and lower limits unless its over the top of pre-existing ones which not recommended surely?

Any further explainations are welcome!
Well you shouldn't really use distance joints. A distant joint is like a solid rod attached to both ends by tying it at that spot with a string. it's gonna rotate, so you'll need multiple distance joints to make anything rigid.. even then it will be wobbly and much less stable than a single joint that does what you were trying to do in the first place.

You'll just have to keep screwing around with stuff to get a feel for it.

Original thread: https://box2d.org/forum/viewtopic.php?t=1056