Rotate depending on the rotation of ground

Hey Guys,

i’m currently working on some jump n run game and i’ve just implemented a little spider which attacks the player if he is in range. I also have an uneven ground and i want the spider to rotate depending on the rotation of the ground.

My code:

if(actualTarget.transform.position.x < transform.position.x)
			transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (-Vector3.right), Time.deltaTime * 10);
			if(Mathf.Round(transform.eulerAngles.y) == 270)
				controller.SimpleMove(forward * crawlSpeed);

Sry if the code is not very good, i’m a newbie. I’ve tried it with a raycast down to get the hit.point, but i don’t know how to go on.

Hope you can help me!

Use to get the current height of your spider and the next position then use these to calculate rotation.