Nash wrote:AFADoomer - can you tell us more about the tank physics and aligning the tank to sloped terrain? Are you sampling from 4 points of the tank and calculating the pitch and roll from there? Is that what the line traces are doing?
Yes, I'm sampling at the four corners of the tank model using GetZAt, calculating the relative offset from floors, then using those values to calculate pitch and roll.
- Code: Select all • Expand view
void SetPitchRoll(Actor mo)
{
if (!mo) { mo = self; }
double points[5], minz = 0x7FFFFFFF, maxz = -0x7FFFFFFF;
points[0] = mo.floorz;
points[1] = mo.GetZAt(Radius, Radius) - points[0];
points[2] = mo.GetZAt(Radius, -Radius) - points[0];
points[3] = mo.GetZAt(-Radius, Radius) - points[0];
points[4] = mo.GetZAt(-Radius, -Radius) - points[0];
for (int i = 1; i <= 4; i++)
{
if (points[i] > MaxStepHeight) { points[i] = 0; } }
double pitchinput = (points[2] + points[1]) - (points[4] + points[3]);
double rollinput = (points[2] + points[4]) - (points[1] + points[3]);
pitchinput = atan(pitchinput / (Radius * 2));
rollinput = atan(rollinput / (Radius * 2));
mo.pitch = clamp(mo.pitch, -30, 30);
mo.roll = clamp(mo.roll, -30, 30);
if (mo.pitch > -pitchinput) { mo.pitch = max(mo.pitch - 1, -pitchinput); }
if (mo.pitch < -pitchinput) { mo.pitch = min(mo.pitch + 1, -pitchinput); }
if (mo.roll > rollinput) { mo.roll = max(mo.roll - 1, rollinput); }
if (mo.roll < rollinput) { mo.roll = min(mo.roll + 1, rollinput); }
}
Still needs to be cleaned up and optimize, but that's the code as it stands now.
HAL9000 wrote:@ Tormentor667
Interesting, thanks for the explanation.
One more question, are tank md3 parts animated or static model?
I wanted to do something similar for my AT-ST, but his body/legs must be frame animated while moving, can your Zscript tank logic handle frames?
For example..AT-ST walking (md3 frames from X to Y) while rotating upper body/turret and shooting.
Cheers
It handles basic animation right now... The treads move when the base of the tank moves. For a proper walking animation, there would probably need to be some added handling for smoothly moving from standing to walking and back, but the core code would still work.