Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-13-2010, 04:30 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
roko is on a distinguished road
Default problem with Chipmunk cpBodyApplyImpulse rotation

Hi all. I have some trouble when i call:

Code:
cpBodeApplyImpulse(cpBody *body, cpVect j, cpVect r)
My problem is that a ball is spinning after i call cpBodeApplyImpulse. How can i change it behavior such that the ball wouldn't spin at all?

here is code of creating of the ball:

Code:
ballSprite = [CCSprite spriteWithFile:@"ball.png"];
		[_tileMap addChild:ballSprite z:2];
		//[self addChild:ballSprite z:3];
		ballSprite.position = cpv(x,y);
		cpBody *someBody = cpBodyNew(10, 10);
		someBody->p = ccp(x, y);
		cpSpaceAddBody(space, someBody);
		player = cpCircleShapeNew(someBody, 10, cpvzero);
		player->e = 0.5f;
		player->u = 0.5f;
		player->data = ballSprite;
		cpSpaceAddShape(space, player);
here is code where i call cpBodeApplyImpulse:

Code:
- (void) ccTouchesBegan: (NSSet *)touches withEvent: (UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	CGPoint pos = [touch locationInView:nil];
	pos = [[CCDirector sharedDirector] convertToGL:pos];	
	if (pos.y>upRect.origin.y && pos.y<upRect.origin.y + 55) {
		CGPoint playerPos = [(CCSprite *)(player->data) position];
		playerPos = [[CCDirector sharedDirector] convertToGL:playerPos];
			cpBodyApplyImpulse(player->body, CGPointMake(playerPos.x, playerPos.y), CGPointMake(playerPos.x, playerPos.y+1000));
		}
}
If need i can attach the rest of my code.
roko is offline   Reply With Quote
Old 11-08-2010, 07:36 AM   #2 (permalink)
kqe
Registered Member
 
Join Date: Nov 2010
Posts: 1
kqe is on a distinguished road
Default

Use

Code:
cpBody *someBody = cpBodyNew(10, INFINITY);
to create your body.

Quote:
Originally Posted by roko View Post
Hi all. I have some trouble when i call:

Code:
cpBodeApplyImpulse(cpBody *body, cpVect j, cpVect r)
My problem is that a ball is spinning after i call cpBodeApplyImpulse. How can i change it behavior such that the ball wouldn't spin at all?

here is code of creating of the ball:

Code:
ballSprite = [CCSprite spriteWithFile:@"ball.png"];
		[_tileMap addChild:ballSprite z:2];
		//[self addChild:ballSprite z:3];
		ballSprite.position = cpv(x,y);
		cpBody *someBody = cpBodyNew(10, 10);
		someBody->p = ccp(x, y);
		cpSpaceAddBody(space, someBody);
		player = cpCircleShapeNew(someBody, 10, cpvzero);
		player->e = 0.5f;
		player->u = 0.5f;
		player->data = ballSprite;
		cpSpaceAddShape(space, player);
here is code where i call cpBodeApplyImpulse:

Code:
- (void) ccTouchesBegan: (NSSet *)touches withEvent: (UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	CGPoint pos = [touch locationInView:nil];
	pos = [[CCDirector sharedDirector] convertToGL:pos];	
	if (pos.y>upRect.origin.y && pos.y<upRect.origin.y + 55) {
		CGPoint playerPos = [(CCSprite *)(player->data) position];
		playerPos = [[CCDirector sharedDirector] convertToGL:playerPos];
			cpBodyApplyImpulse(player->body, CGPointMake(playerPos.x, playerPos.y), CGPointMake(playerPos.x, playerPos.y+1000));
		}
}
If need i can attach the rest of my code.
kqe is offline   Reply With Quote
Old 11-26-2010, 09:02 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
roko is on a distinguished road
Default

kqe, i have sorted it out but anyway thanks you a lot for advance.
roko is offline   Reply With Quote
Reply

Bookmarks

Tags
body, chipmunk physics, problem, spin

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 404
11 members and 393 guests
7twenty7, ChrisYates, djohnson, gmarro, hussain1982, Kirkout, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0