Game Development Community

Average Speed

by Christian · in Torque Game Engine Advanced · 01/11/2012 (6:29 am) · 2 replies

Hey I'm fairly new to coding and I'm stuck trying to get average speed.

All i have so far is

// grabs speed
%velocity = getControlObjectSpeed();
// puts into format i want
%cVelocity = mFloor (%velocity/2);

// i used this code from another page on this forum (think it updates the function every 10th of a second)
%this.speedCheck = %this.schedule(100, "updateSpeed");
// works out top speed that run (gets reset else where)
if (%cVelocity > $LevelSpeed)
$LevelSpeed = %cVelocity;


//this is what i cant figure out

%avg += %cVelocity;

//%timeplayed adds one every 10th of a second
%timeplayed = %this.schedule(100, %i++);

// will divide %avg with %timeplayed
$avgspeed = %avg / %timeplayed;

// echo($avgspeed @ %avg @ %timeplayed);
echo(%avg);
echo(%timeplayed);



%avg needs to add %cVelocity onto its self every time %cVelocity is updated.

About the author

Recent Threads


#1
01/13/2012 (10:49 am)
any one?
#2
01/17/2012 (10:43 am)
Figured it out nvm.