Hey!
I just discovered Box2D yesterday, and it looks great! I've been wanting to create a more physics-driven game for a long time now, but I haven't found a good library to do the hard part for me. But I guess my look is over now. 😉
I've been playing around with Box2D a bit now and I have few, most likely easy to answer questions. I guess I could find the answer on my own by throughly testing stuff, but I figured why not just ask the pros.
My plan is to make a sidescroller, a platformer kind of game. My biggest issue right now is to figure how to work with Box2D and player physics:
1) How do I prevent from the player "rolling", i.e. I want the player only to be able to move sideways, and "lock" the angular velocity.
EDIT. I guess the preventRotation is for this. :p
2) I know that I can move the player by applying forces and/or impulses, but I'm not really sure which one I should use. What is exactly the difference between two? Is an impulse more short-term of an effect or what? Should I use force to move the player sideways, but an impulse to trigger a jump?
3) Right now I'm moving the player with ApplyForce(), but the problem I'm having that the speed of the player becomes way too fast. How do I limit how fast the player can move (also right now the acceleration time to the max speed of the player is too slow, I guess this has to do friction of the player and the ground, I can't really figure how to find out the correct frictions for them). I was trying to play around with GetLinearVelocity and SetLinearVelocity, only changing the x component of it. Am I on the right track?
4) Assume that player is moving to left, and then suddenly changes the direction to right. I want this movement to be pretty much instant, but right now it kind of "lags", because I'm applying a force of same magnitude on the opposite side that the player is already moving to and first the player de-accelerates and then starts accelerating in different direction. This is obviously realistic, but I'm not really looking for realism in this particular case, as it'd compromise how fun the gameplay is.
5) Anyone who has played a platformer knows that you can change a direction mid-air, and that if you stop pressing directional keys (i.e. left or right), the character doesn't "slide in the air". However with Box2D there's no friction in the air, so the player just slides mid-air after jump, as long as he hits ground. What's the best way to implement such air friction, so that the player doesn't slide in the air, but stops (almost) instantly. I guess this has something to do with SetLinearVelocity again?
Also lastly, an irrelevant question, but I'm somewhat of a physics newbie and furthermore english is not my native language, so can someone explain me the difference between forces, impulses and torques (I somewhat understand the first two, just not their actual difference or which one should be used and when).
Thanks for any help to guide my way!
I just discovered Box2D yesterday, and it looks great! I've been wanting to create a more physics-driven game for a long time now, but I haven't found a good library to do the hard part for me. But I guess my look is over now. 😉
I've been playing around with Box2D a bit now and I have few, most likely easy to answer questions. I guess I could find the answer on my own by throughly testing stuff, but I figured why not just ask the pros.
My plan is to make a sidescroller, a platformer kind of game. My biggest issue right now is to figure how to work with Box2D and player physics:
1) How do I prevent from the player "rolling", i.e. I want the player only to be able to move sideways, and "lock" the angular velocity.
EDIT. I guess the preventRotation is for this. :p
2) I know that I can move the player by applying forces and/or impulses, but I'm not really sure which one I should use. What is exactly the difference between two? Is an impulse more short-term of an effect or what? Should I use force to move the player sideways, but an impulse to trigger a jump?
3) Right now I'm moving the player with ApplyForce(), but the problem I'm having that the speed of the player becomes way too fast. How do I limit how fast the player can move (also right now the acceleration time to the max speed of the player is too slow, I guess this has to do friction of the player and the ground, I can't really figure how to find out the correct frictions for them). I was trying to play around with GetLinearVelocity and SetLinearVelocity, only changing the x component of it. Am I on the right track?
4) Assume that player is moving to left, and then suddenly changes the direction to right. I want this movement to be pretty much instant, but right now it kind of "lags", because I'm applying a force of same magnitude on the opposite side that the player is already moving to and first the player de-accelerates and then starts accelerating in different direction. This is obviously realistic, but I'm not really looking for realism in this particular case, as it'd compromise how fun the gameplay is.
5) Anyone who has played a platformer knows that you can change a direction mid-air, and that if you stop pressing directional keys (i.e. left or right), the character doesn't "slide in the air". However with Box2D there's no friction in the air, so the player just slides mid-air after jump, as long as he hits ground. What's the best way to implement such air friction, so that the player doesn't slide in the air, but stops (almost) instantly. I guess this has something to do with SetLinearVelocity again?
Also lastly, an irrelevant question, but I'm somewhat of a physics newbie and furthermore english is not my native language, so can someone explain me the difference between forces, impulses and torques (I somewhat understand the first two, just not their actual difference or which one should be used and when).
Thanks for any help to guide my way!