Jump to content
  • Advertisement
Sign in to follow this  
kaoD

Grappling hook slowly getting larger

This topic is 3034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm implementing a grappling hook into my Java game. I want it to keep its length constant once hooked, therefore creating a circular motion around the hook point.

Here a little scheme: http://img405.imageshack.us/img405/231/esquemaj.png

To keep things simple, I decided to keep with linear motion calc instead of switching to a circular reference system when hooked. My approach to create the circular motion is to get the player speed (yellow in the scheme) and find its orthogonal projection (pink) to the hook vector (blue/green). Then I reverse the orthogonal projection and add it to the player speed, nullifying any speed parallel to the hook vector, so that only orthogonal movement to it is possible, effectively creating a circular motion.

It seems to work, but when I'm hooked, for some reason the hook gets slowly larger, like one pixel per second or so. What could be the cause for that? Maybe it's a precision problem? I doubt so, I'm using doubles, and one pixel per second is like A LOT of precision loss.

Share this post


Link to post
Share on other sites
Advertisement
No it is not a precision problem but a logical one.
As you described you calculated the tangential velocity and used it to move.
Therefore you move away from the circle as the only point the tangent is on the
circle is the one you are currently at.
To fix this problem you have to find the secant that starts in the current position
and ends in the point in the circle that is as far away as the movement would have
gone in the timestep.
To be more accurate I would give you the advice to use the formula of arc-length to determine the point on the circle the movement would end in.

Share this post


Link to post
Share on other sites
Thanks for the quick answer, I would've never found the cause by myself, pretty obscure! But I think I don't understand your solution. Could you please explain it further please?

I think you're talking about simulating the circular motion for the timestep and moving the player there, disregarding velocities? How would I cancel the tangential velocity then? Or you mean just constraining the player positions while it's hooked?

Share this post


Link to post
Share on other sites
A simpler approach may be to calculate the "angle of the dangle" when the grappling hook attaches.

Then increment (or decrement) the angle with time and calculate positions x and y as cosine and sine of the angle times the length of the grapple.

Share this post


Link to post
Share on other sites
Quote:
I decided to keep with linear motion calc...
I assume a simple integration scheme then (e.g. pos += dt * vel). If you wanna avoid trigo, just calculate the new position as you do now. Then measure the distance to the hook and correct to the initial/desired length. Seems you understand vector math so: normalize your pink vector, scale by the length and add it to the hook position (anchor). This way your player won't leave that circle.

This is a rather ad-hoc solution for so-called constrained dynamics, and may have other issues so be warned. But it may work in your case.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!