Reputation: 2131
i am using:
cpVect vector1=cpv(angle, 400);
[body applyForce:vector1 offset:vector1];
but this not working well as needed to put a correct angle using touch screen below line of code used for getting angle
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches )
{
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
float angleRadians = atanf((float)location.y/ (float)location.x-1);
float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians);
float cocosAngle = -1 * angleDegrees;
angle = angleDegrees + 30;
}
}
Upvotes: 0
Views: 1346
Reputation: 2131
Thanks to you all for your precious time to give on that. Finally i found the way to achieve impulse on a chipmunk body on a specific direction. Now i am using below code.
**angle = angle-90; //angle from cctouchesMoved function
float magnitude=shootPower; // magnitude range between 200 to 1000
cpVect impulse = cpv((cos(angle) * magnitude) , -(sin(angle) * magnitude));
[body applyImpulse:impulse offset:cpvzero];**
// applyImpulse gives the right way for putting impulse as needed using above sin and cos theta values.
Upvotes: 1