- Home /
My model from Blender does not follow the AI script properly!
Well I've been making my first unity game, and I've encountered this issue where in game objects, like capsules, will follow the correct AI in the script, however. My imported model from blender does not follow it properly, it works fully, except the part where it's actually supposed to follow me around, seen here in my update video: http://youtu.be/GBU-SYiDFtI?t=54s (Starts at the point of the issue) (I tried adding that controller line into the start function, no difference at all) Screenshot: http://img811.imageshack.us/img811/1608/screenshot20130520at928.png My code looks like this
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 3.0;
var Damping = 6.0;
var controller : CharacterController;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
var attackRepeatTime = 1;
var TheDamage = 20;
private var attackTime : float;
function Start()
{
attackTime = Time.time;
}
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance < attackRange)
{
attack();
}
else if (Distance < chaseRange)
{
chase ();
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase ()
{
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack ()
{
if (Time.time > attackTime)
{
Target.SendMessage("ApplyDamage", TheDamage);
Debug.Log("Enemy has attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function applyDamage ()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance +=40;
}
Please help me, this is really halting my progress! D:
Answer by sparkzbarca · May 19, 2013 at 01:22 PM
thats because controller is a special object which uses a capsule.
Basically your issue is this part here
controller.Move(moveDirection * Time.deltaTime);
that'd be fine except that your imported object doesn't have a character controller attached i'm betting.
thats because if your object did it'd have a capsule around it and your saying it doesnt have a capsule. Character controllers only work with the capsule attached to them.
You can of course select your imported model and add a character controller to it.
I've already done that, I even went and removed the existing one and put another one onto, still nothing, any more ideas?!
oh I see the issue.
You didn't initialize the character controller
start() { controller = CharacterController; }
you created an empty character controller object but didn't assign it to the gameobjects controller.
Ins$$anonymous$$d of leaving us all to guess, how about you supply a screenshot, showing your model in the scene, selected so that the collider is visible, and with the inspector visible so the objects' setup is visible. That would save a lot of guesswork ....
Answer by Bunnybomb7670 · May 19, 2013 at 09:38 PM
Make sure your models forward is forward, that may be the issue.
If it wasn't forward, it's face wouldn't rotate towards me in the video, another side of it would, and it would move sideways if that was the only problem.
Your answer
Follow this Question
Related Questions
BDI Agent Programming in Unity3D 1 Answer
need a logical tip for AI 2 Answers
Tutorials for AngryAnt's Behave 1 Answer
AI in Untiy, best practices 1 Answer
Artificial Intelligence 1 Answer