[java] Mouse follow without easing
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
I don't know if people know what your problem is. I don't. What you are doing looks fine to me.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement