CCPhysicsjoint not keeping the 2 bodies intact
Asked Answered
C

0

7

I want to add a particle body(say Fire) before another physics body(the arrow). So, i am using the spring joint to keep them joined with stiffness around 20000, but still its starting the correct way and the particle-body swings away form the arrow. Here's my code:

fire part

CCParticleSystem *explosion= [CCParticleSystem particleWithFile:@"bomb.plist"];
explosion.position = ccpAdd(projectilePos, ccp(16,0));
explosion.physicsBody.mass=1.0;
explosion.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:16.0    andCenter:explosion.anchorPointInPoints];
explosion.physicsBody.type=CCPhysicsBodyTypeDynamic;
explosion.physicsBody.affectedByGravity=FALSE; 
explosion.physicsBody.allowsRotation=FALSE;  //so that fire flames go upwards only, and not rotate
[physicsWorld addChild:explosion];
explosion.physicsBody.collisionMask=@[];

arrow part

CCSprite *tempSprite;
tempSprite = [CCSprite spriteWithImageNamed:@"[email protected]"];
[tempSprite setScale:0.05];
[tempSprite setScaleY:0.15];
tempSprite.rotation=rotation;
tempSprite.position=dummyBow.position;
tempSprite.name=[NSString stringWithFormat:@"%@,%d",[lifeOfSprite[1] objectForKey:@"name"],[[lifeOfSprite[1] objectForKey:@"life"] intValue]];
tempSprite.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, tempSprite.contentSize} cornerRadius:0]; // 1
tempSprite.physicsBody.collisionGroup = @"playerGroup";
tempSprite.physicsBody.collisionType  = @"projectileCollision";
[physicsWorld addChild:tempSprite z:0];
projectile.physicsBody.mass=100;

now the joint part

[CCPhysicsJoint connectedSpringJointWithBodyA:playerBomb.physicsBody bodyB:projectile.physicsBody anchorA:ccp(1,1) anchorB:ccp(600,0) restLength:0.f stiffness:20000.f damping:60.f];

image loading]![arrow with fire
enter image description here
(debugDraw)
the fire should come at the front, but swings back from front by spring effect

Can anyone tell where's the problem? Thanks in advance.

Courland answered 1/7, 2014 at 11:27 Comment(4)
Try other method connectedDistanceJointWithBodyA.Hayfork
A small change in the joint part.. [CCPhysicsJoint connectedSpringJointWithBodyA:explosion.physicsBody bodyB:tempSprite.physicsBody anchorA:ccp(1,1) anchorB:ccp(600,0) restLength:0.f stiffness:20000.f damping:60.f];Courland
Don't use connectedSpringJointWithBodyA use connectedDistanceJointWithBodyA.Hayfork
i used the distance joint, but when arrow starts moving, the fire-body moves around the arrow keeping the arrow-front as center and radius the string between which gets streched sometimes, kept the min and max distance to 0.0, but still the same problem.. [CCPhysicsJoint connectedDistanceJointWithBodyA:explosion.physicsBody bodyB:tempSprite.physicsBody anchorA:ccp(0.5,0.5) anchorB:ccp(600,0) minDistance:0.0 maxDistance:0.0];Courland

© 2022 - 2024 — McMap. All rights reserved.