I have a custom sprite class in Unity and I'm trying to make a method in where it moves from one point to another. Instead of using an Enumerator for time, I'm using real time game frames using static void methods inside of classes which inherit from a MainGame.cs script attached to the Main Camera, and this is called inside of MainGame's Update() method.
So what I have in the end are the following values: SpriteID OriginalX OriginalY MoveToX MoveToY CurrentFrames TotalFrames
I'm not asking anyone to do the work for me, just that if there's a place I could be directed to in where I could find the math necessary to solve the problem that'd be a huge help. I'm not using any vectors here, just the raw math using only those variables. I don't know if someone has found an answer for calculating it based on update frames...
public class Sprite : MainGame {
public static int State = 0;
public static int CurrentFrames = 0;
public static int TotalFrames = 0;
public static void Move(int SpriteID, int OriginalX, int OriginalY, int MoveToX, int MoveToY, int TotalFrames)
{
switch (State) {
//init
case 0:
CurrentFrames = 0;
State = 1;
break;
//run
case 1:
if (CurrentFrames < TotalFrames) {
//do math here
CurrentFrames++;
}
if (CurrentFrames >= TotalFrames) {
State = 2;
}
break;
//end
case 2:
//Reset values here
//Shut off
State = 3;
break;
}
}
}
EDIT 10212016 456PM: What I've figured out so far, now...
if (CurrentFrames < TotalFrames) {
DistanceX = MoveToX - OrigX;
MoveForwardXFloat = (float)DistanceX / (float)Frames;
OrigX += (int)MoveForwardXFloat;
}