I need to make an Evil Robot move from A to B and back to A. I have managed this so far with the Animation tools built into Untiy. The problem is that the ground is uneven and right now it looks as though the Evil Robot is floating.
Is there a (relatively) easy way to have the Evil Robot move along the ground without keyframing every bump?
I also need the animation to stop when the Evil Robot is shot and have the physics engine kick in but I think I can figure that one out.
Just have your robot’s Y position controlled by a raycast. Fire a ray down to the ground, and adjust your robot’s Y position to move just above the hit point.
Hmm that souns easy and very cool…Jeremy-could you give me a bit more of an idea what you mean? Do you mean to just dra and drop a raycast collider ont the robot? Wouldnt the built in animation settings override the physics and he still have the same problem
Cheers
Aaron
Another way to approach it is to remove the animation. Attach a rigidbody and capsule collider to the robot, check the “freeze rotation” box of the rigidbody, then control your robot with a script like this.
var walkingDistance : int = 0; // set this in the inspector
var turnAmount : int = 0; // set this in the inspector
private var isTurning : boolean = false;
private var counter : int = 0;
function FixedUpdate ()
{
if (!isTurning)
{
// move the robot forward
rigidbody.AddForce(Vector3.fwd);
counter++;
if (counter >= walkingDistance)
{
isTurning = true;
counter = 0;
}
}
else
{
// turn the robot
transform.Rotate(0, 1, 0);
counter++;
if (counter >= turnAmount)
{
isTurning = false;
counter = 0;
}
}
}
I tried adding the Evil Robot to an empty object and then animating the empty object. The Evil Robot walks up and down the terrain as long as there are no large gaps. I used the capsule idea with freeze rotation and got better results than just using a box collider.
I tried using the ray but because I import from LIghtwave. the orientation is all wonky and fwd isn’t fwd.
I also tried the script but couldn’t get a complete walk cycle (A to B and back to A). I suspect that this may also be an orientation issue.
Now all I need to do is stop the animation from the parent so that the Evil Robot doesn’t continue walking after it’s been shot.