Jump to content
  • Advertisement
Sign in to follow this  
ogreblue

[java] Mouse follow without easing

This topic is 5050 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 would like to know how to make something move with respect to the mouse's position without the use of easing. I currently use the formula: xvelocity = (mousex - objectx)/speed; objectx += xvelocity; yvelocity = (mousey - objecty)/speed; objecty += yvelocity; Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
I am sorry I don't think made myself very clear. What I wanted was an object to follow the mouse, but not aquire the mouse's position.
I wanted to have the object move topwards the mouse at a constant velocity, instead in a manner of decelleration as seen in my above example.
Anyway I have found the answer on the javagaming forums and if anyone is interested it is as follows:

float vx, vy, l;
vx = mousex - objectx;
vy = mousey - objecty;
l = Math.sqrt( vx*vx + vy*vy );

if( l <= speed )
{ // We are so close we get there in 1 turn
objectx = mousex;
objecty = mousey;
}
else
{
float scale = speed / l;
objectx += vx * scale;
objecty += vy * scale;
}

Thanks for your help though guys and thanks to crystal squid from
CystalSquid.com

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!