How can I make a b2Body move in a arc-like or curved path? I have heard about cocos2d Bezier curve function (ccBezier) but this is for moving cocos2d sprites. Or can it be modified to move box2d bodies? Any help is appreciated. Thank you.
Don't think that you can modify it to move physical bodies. In case of CCNode subclasses this function uses setPosition: method. If you change position of your body every tick with SetTransform method of b2Body object, it will ignore all possible collisions.
You can try to set linear velocity to physical body. In this case you need to change(rotate) velosity vector as you want.
Related
On tapping on screen I`m gonna apply impulse and angular rotation to sprite to move it to the sides. But after some time OR parameters of physics body attached to sprite should go back to initial (impulse 0, angular speed = 0). What are the best ways to do that (use CCAction or on update detect parameters of physics body and change them to initial)?
If i were in your position, I would probably start a timer at the first collision of the sprite and then use a CCAction to transition to the initial state to make it look smooth. Don't know if its the best way though.
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?
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?
I have played a little with the particle system in cocos2d-iphone and ParticleDesigner, and I use the CCParticleBatchNode to get good performance as I have many of the same emitter. This works great for explosions, but now I would like to have a exhaust smoke on my ships, but here I am stuck.
I can not add the CCParticleBatchNode to my CCSprite's as they can only be added once and it is reused for all exhausts, but how do I then make my CCParticleBatchNode follow or stick to my CCSprite?
Also the exhaust particle system I have made with ParticleDesigner has a gravity/direction, but when my CCSprite's always are moving then is this wrong, should they just emit particles in one place and the movement of the emitter will create the trail, or?
How is this done guys?
of course you cannot add the ParticleBatchNode to the sprite (the same way you cannot add a particle if the sprite were used in a SpriteBatchNode)
to solve similar problems i use to inherit a class from ccsprite, say MySprite, and then override the position setter
-(void) setPosition:(CGPoint) position {
myParticleEmitter.position = position; //+ offsets if needed
[super setPosition:position];
}
You need a pointer to the emitter, i usually keep a weak reference to the emitter from MySprite, and automatically every time i set and change a position the emitter follows.
I didnt quite get the second part of your question, but i think you can just update the gravity direction of the emitter when your sprites moves / rotate, overriding also setRotation if needed
I have been looking all over for help on how to make a CCSprite move and rotate with the movement of a virtual joystick. I have tried examples and sample code, but, none have worked for me. If someone could tell me how to implement a joystick into the HelloWorld layer, that would be wonderful. P.S. The joystick does not need to move the sprite with variable velocity, it just needs to move it in a direction at a constant speed.
Thanks in advance.
First of all, this is a poorly worded question. Normally I would vote you down for this but for some reason I am not going to today.
You say there is no need for variable velocity, but it needs to move in a direction at a constant speed. I assume then that you need a full 360 degree range. What you do is have a joypad sprite on your layer. When you touch the sprite you calculate the angle of the touch (ignoring distance from center since you don't care about variable velocity). Convert the angle to a CGPoint ( ccpForAngle(CGFloat) is helpful for that ) and then use ccpMult(CGPoint, CGFloat) to decide how fast to move your sprite. Then you can use CCMoveBy to move your sprite.
That's one way of doing it at least.