yes i am adding it as static shape, but rehashing every update does make the collision move, since if i press the button and hold it, it does collide, the problem is like while moving a little fast...
i tried adding it as normal shape but then the ball will not collide with any other shape for some reason...
Making a paddle...
-
- Posts: 22
- Joined: Mon May 18, 2009 7:31 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Making a paddle...
It doesn't really matter that much in most case, but rehashing the static hash every frame is much more expensive that just adding the object as an active shape.
I'm guessing the reason why your ball no longer collides with other objects is because your infinite mass paddle collided with your infinite mass static body. That sort of thing tends to generate unsolvable collisions and make lots of NaNs and infinity values for positions and velocities. Use a group or layer to filter out the collision or just rehash the static hash like you are doing (static shapes are never checked for collisions between each other).
Chipmunk does not support swept collisions, so if things are moving too fast they can pass right through each other during a single step. Try using a smaller time value for cpSpaceStep() or don't make your paddle move so fast.
I'm guessing the reason why your ball no longer collides with other objects is because your infinite mass paddle collided with your infinite mass static body. That sort of thing tends to generate unsolvable collisions and make lots of NaNs and infinity values for positions and velocities. Use a group or layer to filter out the collision or just rehash the static hash like you are doing (static shapes are never checked for collisions between each other).
Chipmunk does not support swept collisions, so if things are moving too fast they can pass right through each other during a single step. Try using a smaller time value for cpSpaceStep() or don't make your paddle move so fast.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Mon Apr 05, 2010 12:28 am
- Contact:
Re: Making a paddle...
You mentioned setting the shape's center of gravity...how exactly is this done?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Making a paddle...
You don't set a shape's center of gravity. The center of gravity of a cpBody is simply it's position and shapes are attached with an offset to that.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Mon Apr 05, 2010 12:28 am
- Contact:
Re: Making a paddle...
Thank you very much for this post...it's helped me a great deal to learn more than the basics of chipmunk and I've been able to implement a pinball paddle so I thank you for that.
I do have a question about collision between the ball and the paddle. The collision works very well when the paddle isn't moving and when the paddle moves things go fairly well however the ball goes inside the paddle for a short amount of time and then is launched into the air like it's supposed to...I was wondering if anyone had any tips to lessen this (idealing prevent) this effect
This is how I'm rotating my paddle and my body
and this is how I'm updating the body in the update shape portion of the code
I've tried a lot of things, I've changed the timestep I've lessened the velocity and changed around every number I could possibly think of but what I'm pretty sure is happening is that since I'm moving the rotation of the paddle by 15 each step it's covering the ball at first and then the collision detection is kicking in and then it acts as it should. Are there any tricks you can think of to correct this...if I don't move the rotation by 10-15 the paddle moves to slow and doesn't look real.
Any help you could give would be appreciated
I do have a question about collision between the ball and the paddle. The collision works very well when the paddle isn't moving and when the paddle moves things go fairly well however the ball goes inside the paddle for a short amount of time and then is launched into the air like it's supposed to...I was wondering if anyone had any tips to lessen this (idealing prevent) this effect
This is how I'm rotating my paddle and my body
Code: Select all
if(leftPaddle.rotation > -60){
leftPaddle.rotation = leftPaddle.rotation - 15;}
Code: Select all
cpBodySetAngle(body,-CC_DEGREES_TO_RADIANS(sprite.rotation));
Any help you could give would be appreciated
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Making a paddle...
You also need to be changing the angular velocity to match the change in position. Normally Chipmunk handles this itself, so if you are changing it externally every frame like you are it has no way of knowing this.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 14 guests