Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add to vector length when length is 0 #94

Open
hawkerm opened this issue Jun 9, 2015 · 2 comments
Open

Can't add to vector length when length is 0 #94

hawkerm opened this issue Jun 9, 2015 · 2 comments

Comments

@hawkerm
Copy link

hawkerm commented Jun 9, 2015

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

@viblo
Copy link
Owner

viblo commented Jun 11, 2015

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.

@hawkerm
Copy link
Author

hawkerm commented Jun 11, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants