Rolling forward

if (animation.IsPlaying("roll")) {
		transform.Rotate (7.658, 0, 0);
		transform.Translate (0, 0, 0.4);
	}

Yeah, that code would work to make my character move forwards while rolling, except for the fact that it is rotating every frame, so its always being translated in a different direction. >.< I tried this as well:

if (animation.IsPlaying("roll")) {
		transform.Rotate (7.658, 0, 0);
		transform.Translate (0, 0, 0.4, Space.World);
	}

Which worked, but only in the actual direction “Z”, and not in the direction that the character is facing . What should I do?

If your character is rolling, then you have to get the forward vector in another way, since you are moving it somewhere else.

One way could be to parent this animated character, and then move the parent by getting parent.transform.forward.

Another way could be to calculate the forward vector by Cross product Vector3.up and transform.right (the rotating axis), and then translate in that axis.

.ORG

Maybe you could use the cameras forward. Probably something like:

var mainCam : Camera;
if (animation.IsPlaying("roll"))
{ 
      transform.Rotate (7.658, 0, 0); 
      transform.Translate (mainCam.transform.forward * 0.4); 
}

Daniel, I don’t want it to roll in one direction always, see? I want it to roll in the direction you’re facing, which is unrelated to the camera, whose rotation is static.

It might be easier to make this game using real physics instead of manually trying to roll your ball around. All you have to do is ball.AddForce… it will roll along.

Its not a ball, thats the thing. Its a full character model. Maybe I ought to just include the spinning in the animation.

Here you go:

function Update ()
{
	if (animation.IsPlaying ("roll"))
	{
		var right : Vector3 = transform.TransformDirection (Vector3.right);
		var originalRight : Vector3 = right;
		right.x = originalRight.z;
		right.z = -originalRight.x;
		right *= -1;
		transform.Translate (right * 0.4, Space.World);
		transform.Rotate (7.658, 0, 0);
	}
}

Does this work for you?

Wow, that looks good. >.< But I just incorporated the rolling motion into the animation, so I don’t even need it. Thanks anyways!