Ai code

got scripts? Need scripts?
Post Reply
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Ai code

Post 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;
}
it's VZdaemon on xbox live
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Ai code

Post by hallsofvallhalla »

do you have a collison box setup on the player correctly? What about the terrain?
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Ai code

Post 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.
Image

Image
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: Ai code

Post 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.
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Re: Ai code

Post 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. :) :) :)
it's VZdaemon on xbox live
Post Reply

Return to “Scripting/Coding”