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:@"arrow3@2x.png"];
[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.

Adarsh Roy
  • 69
  • 6
  • Try other method `connectedDistanceJointWithBodyA`. – iphonic Jul 01 '14 at 11:39
  • 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]; – Adarsh Roy Jul 01 '14 at 11:42
  • Don't use `connectedSpringJointWithBodyA` use `connectedDistanceJointWithBodyA`. – iphonic Jul 01 '14 at 11:44
  • 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]; – Adarsh Roy Jul 01 '14 at 11:45

0 Answers0