Length= sqrt(SpeedX*SpeedX + SpeedY*SpeedY);
//Divide by the length to normalise the vector
Newx = SpeedX / Length;
Newy = SpeedY / Length;
//You can then multiply the vector by the ball''s speed and
//the speed should always be the same, whatever direction the
//ball is going in.
Newx *= MoveLength;//This is the length that they will be going.
Newy *= MoveLength;
LastMovedx = (int)Newx;
LastMovedy = (int)Newy;
x += DirX * (int)Newx;
y += DirY * (int)Newy;
So i was guessing I would modify the lines
x += DirX * Newx;
to something like
x += (DirX * NewX) * deltaTime
but that wouldn''t work because delta time is like 25 milleseconds (on my computer, for this game), so it would go way too fast, so maybe i would have to multiply it by a number smaller than one, but then it would get be less exact since it can''t move less than 1 pixel per frame. I don''t know what to do.
Maybe if gamedev fixed their search thing....
t2sherm ô¿ô
Moving things based on frame rate
I know this must have been asked before, but when I try to search i get this crap:
Microsoft OLE DB Provider for SQL Server error ''80040e31''
Timeout expired
/community/forums/Search.asp, line 61
So I was wondering how to move stuff, like a ball on the screen a certain distance, based on what the frame rate was.
This is the code that i currently have to move the ball, so that no matter what angle it is going it is going the same speed. (the angle is just the slope of xspeed & yspeed)
t2sherm ô¿ô
You could do it based on time, like have a velocity you want the ball to travel over 1 second.
vector ballvel;
then, have a time stored that last time you updated the ball in decimal.
float diff = lastupdate - currenttime;
vector movedist = ballvel*diff;
ball_origin += movedist;
vector ballvel;
then, have a time stored that last time you updated the ball in decimal.
float diff = lastupdate - currenttime;
vector movedist = ballvel*diff;
ball_origin += movedist;
you don't change the time, instead you change the distance it's going to travel. say you get 25 milliseconds per frame, and if you want it to travel 25 frames you'd do this:
x+=1*delta
if you want it slower you'd do this
x+=0.1*delta
or whatever
JoeMont001@aol.com www.polarisoft.n3.net
Edited by - Julio on August 4, 2000 1:39:24 PM
x+=1*delta
if you want it slower you'd do this
x+=0.1*delta
or whatever
JoeMont001@aol.com www.polarisoft.n3.net
Edited by - Julio on August 4, 2000 1:39:24 PM
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
yea, i mostly agree with the above two posters.
heres how i do it:
Edited by - POINT on August 5, 2000 5:42:37 AM
heres how i do it:
//this is how far we move in one second - ie the speed measured in units/secconst float DIST_PER_SEC = 10.0f;//note: timeNow and timeOfLastUpdate are also measured in secondsm_vPosition += DIST_PER_SEC * (timeNow - timeOfLastUpdate);timeOfLastUpdate = timeNow;
Edited by - POINT on August 5, 2000 5:42:37 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement