So i made a basic “feeler” enemy AI that is only 2d which means it doesnt go up or down on the y axis. But now i would like to make it be able to walk up stairs or a ramp by felling around. Can anyone point me in the right direction on this? The 2d script im using now is:
var moveSpeed = 3;
var rotateSpeed = 10;
var checkDistance = 3;
var rightCheck : Transform;
var enemyChecker : Transform;
var leftCheck : Transform;
@HideInInspector
var target : Transform;
@HideInInspector
var controller : CharacterController;
function Start ()
{
target = GameObject.FindWithTag("Player").transform;
controller = GetComponent(CharacterController);
}
function Update ()
{
enemyChecker.transform.LookAt(target);
enemyChecker.transform.rotation.x = 0;
enemyChecker.transform.rotation.z = 0;
var hit : RaycastHit;
if (!Physics.Raycast(enemyChecker.transform.position, enemyChecker.transform.forward, hit, checkDistance))
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, enemyChecker.transform.rotation, rotateSpeed/2);
}
if (Physics.Raycast(leftCheck.transform.position, leftCheck.transform.forward, hit, checkDistance))
{
transform.Rotate(Vector3.up * rotateSpeed);
}
if (Physics.Raycast(rightCheck.transform.position, rightCheck.transform.forward, hit, checkDistance))
{
transform.Rotate(Vector3.up * -rotateSpeed);
}
if (Physics.Raycast(leftCheck.transform.position, leftCheck.transform.forward, hit, checkDistance) && Physics.Raycast(rightCheck.transform.position, rightCheck.transform.forward, hit, checkDistance))
{
transform.Rotate(Vector3.up * rotateSpeed);
}
controller.SimpleMove(transform.forward * moveSpeed);
}
@script RequireComponent(CharacterController)
Can anyone point me in the right direction? Thanks!