Hi everyone !
I'm actually working on a game using box2D and I decided to make my character as a b2Body.
The problem is that I wonder how to move it thanks to the pad, going left/right and jump.
For sure I cannot use SetTransform I think because I will break the Physics laws so I ask you which manner is best to do it.
Well, while I'm here, I wanted to ask also two things :
• How do I get if my character is on the floor or over an object (in the air) ?
• How do I delete reactions from the other bodies, I just want it to stop onto the other bodies, not to be pushed by them ?
Thanks a lot.
Well, I've been helped by a friend so now, I've a better system but not totally ready.
I use forces to move my character now, but I want to know when my character is in the air to avoid making him jump again and again.
He told me to use a sensor (set to my character's foot) to tell me when it has contact with the floor or platforms.
So I think I should us IsTouching but I don't get how to use it. Cannot we do such as sensor.IsTouching ? (if sensor is a sensor body)
My question would be : How do I know if my body is set on a platform or on the floor ?
Thanks !
I have always held fast to the belief that one always learns more if one is left to figure it out on his own, but I will offer some advice considering I, not to long ago, asked questions of this nature.
Learn about callbacks and look up the callback objects provided by Box2D.
Think about how you can use the callbacks to your advantage.
Look up the different b2Body parameters and methods and see how they can assist you. (Specifically look at those pertaining to body velocity)
Chances are that if you are under the assumption there is a sensor.IsTouching method provided, you will end up rethinking your entire design. Callbacks are infinitely more effecient than such a brute force method.
Ah, well the way I have collision events set up in my framework, I have no need for using the IsTouching method. I'm using the user data and then in the implemented contact listener, I have the two bodies that are colliding swap data like the game object's numerical ID and the string name through a method in the game object I call onCollide(). The actions resulting from the collisions are handled by the game objects themselves.
In a nutshell, if you want to go the sensor route, you need to find some way to uniquely identify your game objects, then utilize the b2ContactListener to handle the collisions however you see fit. Also, don't forget the user data parameter for the bodies as it can help you greatly.
Trust me, usiong the contact listener is a much better way than brute forcing the process through IsTouching.
Okay thanks, so I guess I'll have to cope with the Contact Listener I didn't understand yet, but I'll try to get it.
I'll ask you if I have any other problem, for now on, I have to deal with another problem with my character's body.
Actually, my character jumps well, but I have a problem when I move it left or right, he goes rapidly too fast, as his velocity never decrease, but it's a problem for me. I want to walk only if I press a pad button, not to accelerate this fast…
How can I manage to avoid such an effet ? Even clearForces doesn't seem to change anything.
Thanks
Well, I think I got it.
For now, only one thing remains problematic : When moving on the left/right, my character stop falling.
When I release the pad, it continues but well… It's as my character was flying sometimes…
In fact I used both but I corrected it !
I was using SetVelocity to prevent it from going too fast, but it's good wo
Hi,
I am trying to create a simple platform style game too. I have a body for the character, a circle, what settings of mass, friction etc should I use to make it move nicely? I use applyforce for jump left and right.....
The other point is that I too use a sensor under the character but am having problems keeping it under an objct that can roll. I have tried setting the position manually and using various joints....
These two issues have been driving me mad 🙂