Original Post
I'm trying to code an iterating semi-circular path along an arbitrary surface. This path will be a guide for an inverse kinematics based walk cycle, where the foot of the creature follows the path. I've got the IK setup, I've got the physics setup, and I've sort of got the path tracing algorithm working. Take this diagram for example :
There we have the 'target' for the foot (red dot). It moves in a semi circle in the x direction, and will only stop when it collides with the surface (green line). Then it will reset and next time a step is taken, it will start at that origin. So switching everything off appart from the target and landscape, you could just have a ball moving across the surface in arcs. This is the test code I've got (some of it shamelessly borrowed from these very forums): Where : ticks = current frame period = total frames origin = origin of circle radius = radius of circle initial = starting point (Radians) cw = clockwise/couter clockwise time = time since last frame The problem I have is that my simulation is real-time, and therefore the circular path drawn is dependant on the frame rate. This obviously causes problems, as when a highly detailed creature is in frame the paths traced become gigantic, and when I look at a low poly part of the landscape the circular path is very small. I'm just wondering if this is the best method for doing this? If so, where would I use the time variable to make the whole thing fps-independant? The two main variables I want control over are the radius of the circle traced (i.e the length of each creature's step), and the speed by which the target moves (i.e the step size between points traced). Any help would be great. [Edited by - SFA on September 8, 2006 12:46:32 PM]
//Update the current step
void Target::incrementStepCycle(float time)
{
if(b_stepFlag == true) //i.e a step is being taken
{
Vector3 mVelocity = CircleAnim(ticks, 60, Vector3(0,0,0),50,1.570,-1, time);
physBody->setVelocity(mVelocity);
ticks=ticks+1;
}
}
//Calculate next position on circle
Vector3 Target::CircleAnim(int ticks, float period, Vector3 origin, int radius, float initial, int cw, float time)
{
float arc = cw * 6.28318f; // arc in cw/ccw
float rop = (1.0f / period); // reciprical of perdiod
// constant motion on a circular path
int posX = origin.x + (int)(radius * cos(initial + arc * ( (ticks * rop))));
int posY = origin.y + (int)(radius * sin(initial + arc * ( (ticks * rop))));
return Vector3(posX,posY,0);
}