Increase x to y withing w milliseconds
Posted: Fri Aug 03, 2012 3:51 pm
Just a quick question.
x = 0; y = 10;
w = 10;
I have number x, and I want x to become y withing w seconds, increasing.
That means that each second, I want x to increase with 1. But I want this function to increase x each frame.
Let's say I want an enemy to walk from the top of the screen to the bottom of the screen. And each frame, a function increases the enemy's y position, so he moves evenly from point A to point B.
I have tried to come up with a function that does this for an hour now(wow!), and I'm stuck.
I want the setup to be like this:
So, what can I put into that function?
x = 0; y = 10;
w = 10;
I have number x, and I want x to become y withing w seconds, increasing.
That means that each second, I want x to increase with 1. But I want this function to increase x each frame.
Let's say I want an enemy to walk from the top of the screen to the bottom of the screen. And each frame, a function increases the enemy's y position, so he moves evenly from point A to point B.
I have tried to come up with a function that does this for an hour now(wow!), and I'm stuck.
I want the setup to be like this:
Code: Select all
float move(float number, float targetNumber, flaot deadLine);
if(enemy.isWalkingFromTopToBottom) {
enemy.y += move(enemy.yPosition, enemy.targetPos, enemy.timeToBeAt_TargetPos); // Value to be changed, The number we are aiming to get to, When we want to be at 'targetPos'
}
float move(float number, float targetNumber, flaot deadLine) {
float i = 0;
/*
Calculate stuff so 'i' contains the number we should increase with in this frame
*/
return i;
}