collision been ignored in an unpredictabble manner

Official forum for the Chipmunk2D Physics Library.
Post Reply
dilsonalkmim
Posts: 4
Joined: Wed Dec 02, 2009 10:45 pm
Contact:

collision been ignored in an unpredictabble manner

Post by dilsonalkmim »

Hi guys,

I have a problem with collisions, in the following scenario:

=> I have six segment shapes (lines, with ratio zero), for wich the body have infinity mass; These lines are been created like that

Code: Select all

   cpBody *bodyLine;
	cpShape *shapeLine;
	
	bodyLine = cpBodyNew(INFINITY, INFINITY);
	
	shapeLine = cpSegmentShapeNew(bodyLine, origem, destino, 0);
	shapeLine->collision_type = 0;
	shapeLine->e = 1.0;
	shapeLine->u = 0.2;
	cpSpaceAddStaticShape(space, shapeLine);
=> I have an object, created as a finity mass body, for which i'm attaching a circle shape, with a moment calculated by cpMomentForCircle passing the values related to the body. Both, the body and the shape are been added to the space, with cpSpaceAddBody and cpSpaceAddShape. For the line segments only the shapes are added to the space:

Code: Select all

cpBody *body = cpBodyNew(m, cpMomentForCircle(100, 50, 50, cpvzero)); 
	body->p = cpv(160, 240)
	cpSpaceAddBody(space, body);
		
	shape = cpCircleShapeNew(body, 50, cpvzero);
	shape->e = 1;
	shape->u = 0.8;
	shape->collision_type = 1;

        cpSpaceAddShape(space, shape);
=> In response to the user interaction, a velocity value is applied to the body, as

Code: Select all

 shape->body->v = velocity_vector;
Everything works nice, but in a few moments, the floating body traverse the static one as if it don't be there. The collision does not happens!!!
I placed a NSLog command to verify if this is due to a specific velocity value, but for a same value, sometimes the collision happens, sometime don't.

I have modified almost every parameter passed to the chipmunk, but unsuccessful.

I have no idea what is wrong.
Can you guys help me with this issue??

Thanks!
Dilson
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by slembcke »

Are you setting the velocity every frame? That can be problematic.

How big is the velocity? If it's too big, it could be passing right through the line in a single step. How big are the steps you are using for each cpSpaceStep()?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dilsonalkmim
Posts: 4
Joined: Wed Dec 02, 2009 10:45 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by dilsonalkmim »

No, i'm setting the velocity only once. After a while, when the velocity decrease to less than a fixed small value, the body is stoped resetting the forces and setting the velocity to zero ( (0,0) ).
The velocity has a length of about 9,25 * vector of length 215 units, and the step rate is 1/60. Its to high ??
I have tried step rate values ranging from 1/400 to 1/10, but with no success.

Tks a lot!
Dilson
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by slembcke »

Hmm. Sounds like that's not the issue then. Are you sure you aren't accidentally freeing the object somewhere?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dilsonalkmim
Posts: 4
Joined: Wed Dec 02, 2009 10:45 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by dilsonalkmim »

What did you mean with "Freeing the object"? cpBodyFree?? I don't do that.
I have noted the problem ocurr when the floating body is close to the static line.

My space have no gravity, but damping value of 0.01, so the body deaccelerate with time.

The code that control the movement look like this:

cpSpaceHashEach isn't called, because i have my own timer calling cpSpaceStep method and my updatePositioning method.

Code: Select all

-(void)stopBody {
	myBody->v = cpv(0,0);
	cpBodyResetForces(myBody);
}

-(void) updatePositionig {
	//set body representation position to myBody->p
	//set body representation rotation to myBody->a
}

-(void)run {
	[self disableUserInteraction];
	
	myBody->v = velocity_value;

	timer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(nextStep) userInfo:nil repeats:YES];
}

-(void)nextStep {

	cpSpaceStep(space, 1.0f/60.0f);

	//cpSpaceHashEach(space->activeShapes, &updatePositioning, nil);
	[self updatePositioning];

	//stoped is calculated comparing actual velocity value against a fixed small value (cpvlength(velocity) < 15)
	if(stoped) {
		[self stopBody];

		[timer invalidate];
		timer = nil;

		[self enableUserInteraction];
	}
}

-(void)userEvent {
	[self run];
}
Tks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by slembcke »

You are explicitly setting the position and angle in your updatePositioning method. That can be bad. What exactly are you doing in that method.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dilsonalkmim
Posts: 4
Joined: Wed Dec 02, 2009 10:45 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by dilsonalkmim »

I have an UIView *myBodyView, that is updated with position/angle taken from cpBody

Code: Select all

  -(void) updatePositioning {
      myBodyView.center = myBody->p;
      myBodyView.transform =  CGAffineTransformMakeRotation(myBody->a);
   }
 
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: collision been ignored in an unpredictabble manner

Post by slembcke »

Ah, just updating graphics based on the body. I thought you meant you were doing body->p = something.

Can you make a video of the problem? I'm not sure I have any other ideas without seeing exactly what is happening.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests