Unity Game Object Problem

Hi,

I’ve been working on a game for some time now and came to these forums for assistance a few times and this has been a great place for getting help so thank you. Unfortunately, I have encountered another problem. I have models for enemies that have a basic AI script attached to them, and some of the game play involves narrow corridors, but the enemies are able to completely pass through walls in to different sections of the building/map. I’ve set the imported building model to Generate Colliders, same set up for the enemy model. Any idea why they’re still passing through walls?

How are the objects represented for the purpose of collision detection and response? Rigid bodies? Character controllers?

Also, how are you moving them?

It is basically done by finding the position of the objects and calculating the distance between them. Now that you say that, I presume I’d have to use raycasting to check for collisions with terrain? I currently just have simple box colliders on the enemies to detect when they’re being shot.

It sounds like the problem is how you are moving them. You either need to move the object “physically” using some sort of Rigidbody movement such as AddForce() or use CharacterController.Move().

If you have to use your current movement system. Then you should look into rigidbody.SweepTest() or Physics.CapsuleCast() to get check in an area wider than a raycast.

I see, thank you for the replies. I would go and redo my whole AI but I joined a course late and haven’t had a lot of time to complete the assignment so it’s not a matter of I HAVE to use that particular movement script it’s just I don’t have time to learn about more efficient alternatives.

Mr current AI Script:

var player : GameObject; 
var speed : float=6f; 
var range : float=15f;
var hitRange : float=6f;
var enemyDamage : float=10f;
var rotationSpeed : float=5f;
var damageTimer : float=0f;
var delta : Vector3;
var distance;

function Start()
{
	player = GameObject.Find("First Person Controller");
}

function Update()
{
	//move towards player
	distance = Vector3.Distance(transform.position, player.transform.position);
	if(distance<=range)
	{	
		MoveTowards();
		RotateTowards();
		AttackPlayer();
	}
}

function MoveTowards()
{
	delta = player.transform.position - transform.position;
	delta.Normalize();
	delta.y = 0;
	if(distance<=(hitRange/1.5))
	{
		return;
	}
	var moveSpeed = speed * Time.deltaTime;
	transform.position = transform.position + (delta * moveSpeed);
}

function RotateTowards()
{
	transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(delta), rotationSpeed);
	transform.rotation = Quaternion.Euler(270, transform.eulerAngles.y, 0);
}

function AttackPlayer()
{
	damageTimer+=Time.deltaTime;
	if (distance < hitRange  damageTimer>=1.5)
	{
		audio.Play();
		damageTimer=0f;
		player.SendMessageUpwards
		("ApplyDamage", enemyDamage, SendMessageOptions.DontRequireReceiver);
	}
}