Life has a new enemy with legs, AI and terrain hugging abilities. It is not a robot you want near your plants :-)
The walker use Unity IK rigging and animation with a VFX for flames and particles. Here is the code controlling the body so it angles itself in relation to the legs with smooth and deadZone.
public Transform footLB;
public Transform footLF;
public Transform footRB;
public Transform footRF;
public float rotateMultiplier = 1f;
public float currentXrot;
public float currentZrot;
public float targetXrot;
public float targetZrot;
public float rotPerFrame = 0.1f;
public float deadZone = 0.2f;
// X is back front
// Z is left right
// Update is called once per frame
void Update()
{
float avgLeft = footLB.localPosition.y + footLF.localPosition.y;
float avgRight = footRB.localPosition.y + footRF.localPosition.y;
float avgFront = footLF.localPosition.y + footRF.localPosition.y;
float avgBack = footLB.localPosition.y + footRB.localPosition.y;
targetXrot = (avgBack - avgFront);
targetZrot = (avgRight - avgLeft);
if (targetXrot - deadZone > currentXrot)
{
currentXrot += rotPerFrame;
}
if (targetXrot + deadZone < currentXrot)
{
currentXrot -= rotPerFrame;
}
if (targetZrot - deadZone > currentZrot)
{
currentZrot += rotPerFrame;
}
if (targetZrot + deadZone < currentZrot)
{
currentZrot -= rotPerFrame;
}
transform.localEulerAngles = new Vector3(currentXrot * rotateMultiplier, transform.localEulerAngles.y, currentZrot * rotateMultiplier);
}
Here you can see the terrain painter in action as the plants are consumed by the walker.
The end result with nav AI and plant range finding. And a rough terrain manipulation. I hope to make it using masks instead of handcoded pixels.