Essentially I'm trying to create a body that is always oriented to the direction it is traveling after impacting another shape. If I specify a typical inertial then the object is imparted angular velocity after it impacts an object, causing it to rotate continuously. If I specify infinite inertia then the object's rotation never changes. It may be possible to specify a damping value that quickly diminishes the angular velocity, but that also influences the regular velocity, which I don't want. I've tried setting body->w to zero each step, but that has the same result as infinite inertia.
I can brute force this by setting a flag in my higher-level construct, and setting the rotation manually after each collision, but I would prefer to achieve this purely within Chipmunk if possible.
Thanks!
Rotation bound to velocity vector
-
- Posts: 3
- Joined: Tue Jan 13, 2009 7:57 am
- Contact:
-
- Posts: 56
- Joined: Tue Sep 11, 2007 2:30 pm
- Contact:
Re: Rotation bound to velocity vector
I've done something which sounds a bit like what you want in a game I'm working on. In this game you can shoot arrows, which always point in the direction they're travelling. I connect all arrow-bodies to the static body with a cpDampedRotarySpring. Every frame, I update the spring's restAngle to be the same direction as the arrow's velocity. (I also set the stiffness to be cpvlengthsq(velocity) and the damping to be cpvlengthsq(velocity) / 500.0, but you can play around with the stiffness and the damping to find values that work for you.)
-
- Posts: 3
- Joined: Tue Jan 13, 2009 7:57 am
- Contact:
Re: Rotation bound to velocity vector
Thanks. I've already added a higher-level solution in. When a collision occurs I normalize the velocity vector, then atan2 the x and -y to convert to radians. This is working perfectly, and no extra processing is required unless an impact actually occurs. This motion is all linear with no gravity so my problem was relatively easy to fix compared to yours.
-
- Posts: 56
- Joined: Tue Sep 11, 2007 2:30 pm
- Contact:
Re: Rotation bound to velocity vector
Yeah, if you don't have gravity then you don't need to do something every frame. You could still use a rotary spring to set the the direction if you wanted the rotation to the new direction to be smooth rather than instantaneous, but that would be a purely cosmetic change, since you already have something that works.
Who is online
Users browsing this forum: No registered users and 20 guests