pymunk icon indicating copy to clipboard operation
pymunk copied to clipboard

Can't add to vector length when length is 0

Open hawkerm opened this issue 9 years ago • 2 comments

Would be nice for it to remember the last 'direction' it was in to be able to up it's speed once an object has stopped.

Currently throws: File "pymunk\vec2d.pyo", line 310, in __setlength ZeroDivisionError: float division by zero

Though with the convention set in get_angle that the angle is zero if the length is zero, I would at least expect it to increase the vector in that direction.

Thanks

hawkerm avatar Jun 09 '15 03:06 hawkerm

From the user's point of view this seems like a reasonable request, I can see how it would be useful.

However, Im a bit concerned about two things:

  1. It requires an extra field on the Vec2d class (50% bigger in size), are there any performance implications maybe?
  2. The vector doesnt "exist" for the pymunk objects until you ask for it. So, if you get the velocity from a Body in one frame, and then ask for it again the next frame it wont use the same vector, instead it creates a new one from a X value and a Y value kept in the underlying c code . And if the new one is 0,0 it cant remember its previous velocity, since it didnt exist at that time, it was a different vector.

The second one is the most serious one, I dont immediately see what a good solution would be.. Not sure if this feature would be useful if you couldnt use it to keep the information about pymunk objects, only free Vec2d objects.

viblo avatar Jun 11 '15 02:06 viblo

I see, thanks for the extra info, didn't realize about point # 2. That certainly seems like a challenge. Almost seems like a request for Chipmunk directly then.

In my current project I'm now caching the vector so if it's 0,0 I grab the cached one and use that to perform my calculation.

hawkerm avatar Jun 11 '15 02:06 hawkerm