Make hamster inside ball rotate to face direction of travel?

I’m trying to make a 3D hamster mesh placed inside of a separate ball mesh rotate to face the direction the ball is traveling in. I’m new to coding in javascript.

The ball rolls exactly how I want it to, I just want to put the hamster object in it and make the hamster turn to face in whatever direction the ball is rolling in.

  1. Does the hamster need to have a mesh collider with gravity, rigidbody, etc?

  2. I tried using LookAt, the follow transform, RotateAround, just about everything I can think of, including solutions given to similar questions on this forum. Spent 8 hours trying to figure it out. Help appreciated :slight_smile:

Ball movement script (if this helps):

var up = 15;
var down = -15;
var east = -15;
var west = 15;
var cam : Transform;
var jumpSpeed = 500;

function Jump()
	{
		rigidbody.AddForce(Vector3.up * jumpSpeed);
	}

// Update is called once per frame
function Update () {



if (Input.GetKey("up"))
{
	rigidbody.AddForce(cam.transform.forward * up);
}

if (Input.GetKey("down"))
{
	rigidbody.AddForce(cam.transform.forward * down);
}

if (Input.GetKey("left"))
{
	rigidbody.AddForce(cam.transform.right * east);
}

if (Input.GetKey("right"))
{
	rigidbody.AddForce(cam.transform.right * west);
}

if(Input.GetKey("space")) 
		{
			Jump();
			
		}

I’d probably simulate the positioning of the hamster in the ball rather than try and use Physics. Colliders are one sided, so you’d have to create a second ‘ball’ with the normal reversed inside the outer ball just as a starting point if you wanted to get real physics working. And I fear there would be a lot more issues. You could start with something like this in Update():

transform.position = ball.position + Vector3.down * someValue;

If you constructed your hamster correctly (front of the hamster facing positive ‘z’ with the rotation is (0,0,0), you should be able to get him to face the correct direction by:

transform.rotation = Quaternion.LookRotation(ball.rigidbody.velocity);