Enemy Collision Detection

I have a little problem that I hope someone can help me with. I’ve written a simple “follow the player” script that basically calculates the distance between the two GameObjects and normalizes it. There’s some minimum and maximum if statements in there just so the object starts following at a certain distance and stops following when it gets close enough. This all works fine. My problem is that the object following the player has no collision detection. It has a Character Controller on it, and I’ve even tried Rigid Bodies. Nothing works. Is there something I need to do to help the object climb steps when following the player up a flight of stairs or to at least bump into a wall when the player goes around it?

Thanks in advance.

i suggest this (perhaps follow the leader and obstacle avoidance):
http://www.red3d.com/cwr/steer/

without any code its diffcult to help you. u can adjust stair climbing at the char controller. how do u check the collision? and have u checked this?:

collision action matrix at the bottom

This is the whole script for following the player. I set the LookAtPlayer variable to find it in the camera.target since I also want to be able to switch between the two characters. I think my problem lies at the end of the script because I want to limit the follower from completely rotating upward when the player jumps. But this still doesn’t explain why the follower runs through walls. As a test, I’m just using two simple capsules with colliders on them.

// These variables are to stop the follower from floating in the air when the player jumps
private var LookAtPlayer : Transform;
var damp = 1.0;

var rotateSpeed = 5.0;
var jumpSpeed = 7.0;
var gravity = 5.0;

private var running = false;
private var grounded = false;
private var moveDirection = Vector3.zero;
//The "stop floating" variables end here

//These variables are for the follower
var enemy : Transform;
var player : GameObject;
var dir : Vector3;
var speed = 0.14;
var observed : boolean;
var sightDistance = 7;

function Update () {
		//for looking at the player -- add an if statement later if the player is under attack, and then the follower needs
		//to look at the enemy
		LookAtPlayer = gameObject.Find("MainCamera").GetComponent("CamSmoothFollow").target; //This defines what to look at
		if(LookAtPlayer){
			var rotate = Quaternion.LookRotation(LookAtPlayer.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
		}
				
		//Controls the distance of the follower
		if (Vector3.Distance(player.transform.position, transform.position) > sightDistance){
if (observed){
		dir = player.transform.position - transform.position;  //the distance between the player and the follower
		dir = dir.normalized;  //move towards the player
		
		transform.Translate(dir * speed, Space.World);
		//when player runs, the follower should also run
		if(Input.GetButton("LeftShift")){
			speed = 0.25;
		}
		else{
			speed = 0.13;
		}
	}
	else {
		transform.eulerAngles.y = Mathf.PingPong(Time.time * 20,90) -45;
		}
	}
}

function OnTriggerEnter(other:Collider) {
	if (player) observed = true;  //This executes the follow script
}
//This executes the "Stop floating" procedure
function FixedUpdate () {
	var controller : CharacterController = GetComponent(CharacterController);
	moveDirection.y -= gravity * Time.deltaTime;
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;
	if (grounded) return;
}

I hope you can help. I’m getting used to javaScript, but I don’t know anything about C coding.

Depending on your needs, perhaps a spring joint can do the entire job. The follower must be a regular rigid body with a collider though, no character controller.

the problem is that transform.Translate ignores collsion if i am informed right.
u could use a char controller on the follower and use move() to move him, too. this way he wont run through walls.

as i said, you should realy check the link. its pretty easy to implement and if its done it works great:
http://www.red3d.com/cwr/steer/

and what Jasper said sound good, too =)

I think I know what the problem is: You’re using transform.Translate. What that does is that it moves in the direction of your choice and if there’s something in the way it simply moves through it. At least that has happened to me and I think I know why: It’s because transform.Translate is just changing the position of the object(not moving) in the direction that you’ve chosen for it, so that it looks like you’re moving. (At least that’s what I think ,but I could be wrong).
In that case, that means that if there’s something in the way of it, it will still change it’s position in the same direction and then get ‘inside of the other object’.

Seems like immerhart got before me on this point-_-. We must have been replying at the same update time.

Thanks guys for your help. At least now I have a name for the problem. Is there a way around the transform.Translate? I tried using gameObject.Move, but this doesn’t work either. I get an error that says its not compatable with Space.World.