Page 1 of 1

Ai code

Posted: Mon Jan 24, 2011 3:37 pm
by VZdemon
i'm trying to make a capsol move aourd in random directions. but the problem in when ever it moves forward in ignores collitions and just goes strait in to the terrian. here is my code if anyone could help that would be awsome.

Code: Select all

var speed : float = 6.0;
var rotateSpeed = 3.0;
var gravity : float = 20.0;
var prefab : GameObject;
var saveTime = 0;
private var turnTime = 3;

function Update() {
	moveDirection.Vector3.forward;
	if(Time.time > saveTime){
	turnTime = Time.time + saveTime;
	transform.Rotate(Vector3.up, Time.deltaTime * rotateSpeed, Space.World);
	}
	moveDirection.y -= gravity * Time.deltaTime;
}

Re: Ai code

Posted: Mon Jan 24, 2011 4:33 pm
by hallsofvallhalla
do you have a collison box setup on the player correctly? What about the terrain?

Re: Ai code

Posted: Mon Jan 24, 2011 4:42 pm
by SpiritWebb
You have to use raycasting if you want to go up hill. I have this same problem right now. OR you could try adding a mesh collider rather then a box collider.

Re: Ai code

Posted: Mon Jan 24, 2011 5:36 pm
by Sakar
The problem is that you're directly modifying it's position. You'll either need to use raycasting to detect if it will collide and stop it from moving, or use a character controller and use it's movement commands, which handle it for you. The disadvantage to character controllers, however, is that too many can easily slow down the game.

Re: Ai code

Posted: Thu Jan 27, 2011 3:36 pm
by VZdemon
yhea i figuerd that it ignores the collitision becuase i'm transforming it's position instead of moving it forward. but i don't know much about unity's js or cs and niether do i know anything about array casting so if someone could help me with some code it would be greate. thanks everyone for reading and replaying. :) :) :)