Some hints:
1. You still have offset on the circle shape (I see that I wrote
offset on the body and not on the shape in my previous post, sorry).
Its not needed and will just confuse you, so just send in (0,0)
instead

2. You will have to decide if you want pymunk to resolve collisions
for you or if you just want pymunk to detect them. If you _do not
want_ pymunk to actually resolve collisions you should return False
from the callback (or otherwise make sure pymunk never tries to
resolve a collision). For the next pointers I will assume you _want_
pymunk to resolve collisions for you.

3. The move function is very strange, it doesnt even do anything with
the x and y it gets as parameters! :) I suggest you remove it
completely as I don't understand why you need it. And remove those
old_x/old_y variables as well. And change the update function to only
synchronize the body position in the pymunk world with the sprite
position in the pyglet world:
def update(self): x,y = self.body.position

4. You don't need to do anything in the collision callback function.
Remove it (or keep it and just use it to print info for debugging).
pymunk will move the shapes/bodies for you

Later on you will want to use another way to move the car by player
input and not just -+ on the position, but I think its good if you
straighten out the other stuff first :) There are some threads on the
chipmunk forum (http://www.slembcke.net/forums/viewforum.php?f=1) that
deals with top down cars that might be usefull to get this part right.
(just search on it for topdown and "top down" and you will find them).
Another thing I noticed is that you create pymunk vectors before you
send them in to functions. This is usually not needed so you can save
some space with writing it as a normal python tuple instead ((x,y)
instead of pymunk.Vec2d(x,y)). And I see that you got some spaces
mixed with tabs when you added the debug code. Its usually a very good
idea to keep to one form, either tabs or spaces, not both. But you
probably know that already :)

Maybe I can put together some simple example when I get home today,
but I can't promise anything.

/vb
(Now when I see your code I see that I forgot the moon buggy example,
but it looks like you found it. When I said pyglet example I meant
box2d_pyramid.py (or something like that) :))

On Aug 10, 6:39 pm, dorzey <[email protected]> wrote:
> I do indeed have collisions! The pymunk example you pointed to was
> very useful; especially for drawing the body so I can see where it is.
>
> However, I'm still struggling with updating the sprites when a
> collision happens.  I've updated the pastebin(http://pastebin.com/
> f3ae6b483) with my latest effort.  I can successfully update the
> sprite and body from user input, but not when a collision occurs as
> the bodies become 'detached' from the sprite.
>
> Dorzey
>
> On Aug 9, 9:37 pm, viblo <[email protected]> wrote:
>
> > The main problem is that you set an offset to the body, even when you
> > have changed the image to have its center in the middle. If you remove
> > the offset from the body you will get collisions when the circles
> > overlap. (You had collisions all the time, just that they didn't occur
> > where you would expect :)
>
> > Another problem is that as soon as the two circles collide they will
> > move in the "physics world" but you never update their pyglet
> > positions based on this fact. If you don't want them to move, you can
> > return false from the collision callback function (then pymunk wont
> > move the bodies to resolve the collision). Otherwise you have to
> > update the pyglet car sprite positions from the bodies.
>
> > I don't know if you have seen it but there is one very small pyglet
> > example included with pymunk (the src dist). However, I don't think it
> > will give you much help as it draws the screen directly from the
> > pymunk objects and doesnt use pyglet sprites at all.
>
> > note: With the newest release pymunk will automatically reorder the
> > vertices if they are in the wrong order (unless its told not to).
> > Another useful tip If you are uncertain about the polygon winding is
> > to use pymunk.util.is_clockwise(..) or even simpler, just reverse the
> > list and see if things improve :)
>
> > /vb
>
> > On Aug 8, 2:31 am, dorzey <[email protected]> wrote:
>
> > > I'm trying to create my first game and after some research it seems
> > > pymunk might be a nice way to add some physics to my top down racing
> > > game; or at least take care of collisions for me.
>
> > > However, my attempt (http://pastebin.com/m6d5a81c1) to use it has
> > > faltered.  Whilst the body, shape and sprite all seem to be having
> > > their position updated correctly my program fails to recognise, and
> > > then handle, the collision. What am I doing wrong?
>
> > > I'm probably missing something really obvious, but google and the
> > > pymunk api don't seem to hold the answer.
>
> > > I'd also be interested in links to any tutorials/examples on using
> > > pymunk with pyglet.
>
> > > Thanks,
>
> > > Dorzey
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to