# AI enemy vechicle problem

 0 I want to know about script for control a tank. I can make it look at and follow player but I have some problem. the enemy tank don't see player it will move to straight and when it move to something such as a wall or bigstone it can't turn away from that object so the enemy tank will fools because it can't move to anywhere. more ▼ asked Apr 30 '12 at 04:41 AM frame_th 15 ● 2 ● 3 ● 4 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 Latest tutorial upload for all of you Unity folks. This is a video that will help you get simple AI going in your racing or traffic games. The video includes a 1.4MB download of the entire Unity project seen in this tutorial (look in the video description).http://www.youtube.com/watch?v=VbBY_jezoDI&feature=youtu.be more ▼ answered Dec 22 '12 at 07:42 PM add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 That's not an easy question - avoiding obstacles is a complex task. In this case, maybe you could use the following algorithm: each Update, cast a short ray forward; if nothing is hit, move the tank; if it hits something, enter a state where the tank will rotate a fixed angle (15 degrees, for instance) then return to idle state, where it will again verify obstacles ahead - something like this: ```enum State {Idle, Chase, Attack, TurnLeft, TurnRight}; var state: State = State.Idle; var turnSpeed: float = 60; // 60 degrees per second var length: float = 8; // "see" 8 units ahead private var turnAngle: float = 0; function Update(){ switch (state){ case State.Chase: // chase the player case State.Idle: if (!Physics.Raycast(transform.position, transform.forward, length)){ // move the tank forward if no obstacles ahead } else { // if some obstacle in range, enter turn right state: state = State.TurnRight; turnAngle = 15; } break; case State.TurnRight: // stay in turn mode until turnAngle ends: var dAngle = turnSpeed * Time.deltaTime; transform.Rotate(0, dAngle, 0); turnAngle -= dAngle; // when turnAngle ended, return to idle state: if (turnAngle ``` more ▼ answered Apr 30 '12 at 05:10 AM aldonaletto 42.5k ● 16 ● 43 ● 202 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x982
x60
x36
x4

asked: Apr 30 '12 at 04:41 AM

Seen: 536 times

Last Updated: Dec 22 '12 at 07:42 PM