I'm trying to determine the angle during the collision between two box2d bodies in my contact listener (and have failed).
I actually just want to establish whether a collision was simply a glancing blow or a more direct hit - I had hoped to use the relative angle between the two dynamic object (which could be at any angle of rotation and could be polygon or circle) to flag the object for action outside the time step. I guess it would be best to establish the angle at EndContact or PostSolve.
I'm sure this can't be too hard - Box2d must determine this.
Any help greatly appreciated.
Have you checked Ray's tutorial on Collision Detection in Box2d?
Related
I am building an IOS game in Cocos2d - Chipmunk - Spritebuilder. I need to make a characters orbit around around a point, and I was having quite some difficulty in implementing orbits with real physics.
So far, I have tried two methods, one is creating a distance joint from the player to the planet, and then applying a 90 degree force on the player where an angle is created between the end of the distance joint and an imaginary line drawn at a 90 angle to it. He moves around crazily and this method is not working for me.
I then tried calculating 180 points on the circumference at a radius from the planet (which is the bounds of detecting and implementing its effects on the player) - and then in a scheduled update method [character.physicsbody applyForce:nextCircumferencePoint]; This does not work, as he does not follow the path exactly and is quite far from it. I am thinking that I need to also apply a gravitational force towards the planet which would cause him to circle it. Though I don't know how to calculate that force, apply it, or if it would even help.
A third method which would never work, but was used for testing was to set his position to the next circumference point. He does orbit, but any collision won't work (such as if a piece of space junk goes in his way.) He will simply be positioned right over any other object. This world great if you don't need collisions, are writing your own physics engine. This is not a polished way of doing things, so will avoid it.
Please correct anything I have already done and tell me how it would work, or shed light on other options and how to implement them.
Check out my answer here. It's for box2d, but you can do it with Chipmunk. If bodyA position will change, orbit will be same. You just need to change speed of body movement for your needs, just increase smoothness and slow down your update method.
I have made a rigid body for the player and have been trying to get the rigid body moving along with the player's controls.
What I mean is that whenever I press forward I want the rigid body to move forward in the direction the player is facing, same with back, left, right. So far I'm able to use apply force to move the rigid body in static directions.
My straight question is how do I move the player's rigid body in the direction the player is facing.
Other Details:
I don't really want to use kinematic bodies if not necessary mostly because their very fiddly at the moment
I'm using glfw3 for input
This is quite amazing that you would not see how to do that after you actually managed to apply forces in static directions to something you configured over bullet.
Come on, you HAVE the skill to figure it out.
Here, just a push in the direction (hehe), hem. Just take the vector of the facing direction (which could be determined by camera, 1st or 3rd view, or even something else...).
Congrats, this vector is your force by a k factor.
You should also modulate this force according to speed, you don't need to accelerate to infinite speed, just accelerate lots at first and then regulate force to tend to desired walk speed.
Then, the side directions are obtained by rotating the facing vector by 90 degrees around the standing axis (most surely the vertical). You can obtain that by simply swapping components and multiplying by -1 one of them. x,y,z becomes y,-x,z
To go backward, its just -x, -y, -z on the facing vector.
So your up key is not bound to 0,1,0 but to facing_dir actually. This facing dir can change with mouse or some other view controls, like numeric keys 2,6,8,4 for example. Or you could drop up,left,right,down for movement and use w,a,s,d like everybody else, and use direction keys to rotate facing direction. (+mouse)
It is much more difficult to obtain the facing vector from mouse movement or direction keys than finding out how to apply the force, so if you already have the facing vector I'm puzzled that you even have a problem.
I've searched extensively on how to make a Box2d body move along a Bezier curve or arc-like path with a start point, end point and possibly another control point. I know cocos2d objects can be moved around using ccBezier but how can it be done for Box2d bodies? Please help. Thanks in advance.
I have tried to move a box2d body using a curve (making a spider walk around an asteroid). I found that using SetTransform every frame worked, but it made the collision response in the engine fail.
I was able to find a much better solution by using prismatic joints. You create a joint starting at the position (p0) you want to start from and pointed towards the next waypoint (p1). Then you let the joint push the body from p0 to p1 using the motor. When the body gets very close to the next point, destroy the joint and form a new one for the next two points. The body will still have its velocity so the motion looks smooth.
I put a more complete post on this on Stack Overflow here.
Was this helpful?
Using Cocos2d and Box2d I have made a rope of revolute joint segments with a body attached to the lowest segment (weldJoint) which I move using a mouse joint. The rope is hanging downward. How can I set conditions to tell when the attached body has covered double the distance it is swiped (mouseJoint) in the opposite direction. For example, if I swipe the body (attached to the rope) 45 degrees to the left I should know (maybe by some message or something) when it swings back 45 degrees to the right. Please help.
Perhaps I'm oversimplifying, but have you tried adding a sensor (Section 6.3 of Box2dManual) when you release it? If your physics are pretty simple, you should be able to get away with adding it at the same Y as the release point and making it's X flipped about the joint location.
I'm new to using Box2d and really can't find a consistent answer to my question so please excuse me.
I'm writing a game for the iPhone -- who isn't these days -- and I'm using Cocos2d and Box2D. I have objects that move around in the game and I would like to give them a more of a curved path. From my studies I know that I should use body of type b2_kinematicBody which allows me to change the linear velocity every tick and keeps them from colliding with my other flying bodies. I do understand that if I know my current position (x,y) and my next position in the step (x1,y1) I would be able to compute the vector for velocity. Does anybody have a good way to give an object a defined curved path? I'm thinking it has to be some kind of parametric equation.
Take a look at bezier curves. After curve defenition you can compute the derivative (it's easy for bezier) and use it as a velocity for your body
OH whats the game called? sounds like a good one. have you looked into maybe just doing that in version 2.0