- Home /
Help! the enemy incline when attacks player
I add to script to Model with animation
But the enemy incline
Look:
the IA enemy script requires audio source adn Fps Input controller
this is:
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 5.0;
var Damping = 6.0;
var attackRepeatTime = 1;
var TheDammage = 40;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
var Troll : AudioSource;
var Zombie : GameObject; //The Model who contains the animations
private var MoveDirection : Vector3 = Vector3.zero;
function Start ()
{
attackTime = Time.time;
}
function Update ()
{
if(RespawnMenuV2.playerIsDead == false)
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance > lookAtDistance)
{
}
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 ()
{
Troll.Play();
Zombie.animation.Play("Walking", PlayMode.StopAll);
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack ()
{
Zombie.animation.Play("Attacking", PlayMode.StopAll);
if (Time.time > attackTime)
{
Target.SendMessage("ApplyDammage", TheDammage);
Debug.Log("The Enemy Has Attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function ApplyDammage ()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance += 40;
}
Help me please :(
Answer by RetepTrun · Jan 09, 2015 at 02:18 AM
Probly center of player is higher than that of the enemy so as they get closer the angle increases. Try this.
Vector3 lookpos = Target.position;
lookpos.y = transform.position.y;
var rotation = Quaternion.LookRotation(lookpos - transform.position);
But I in where put it?
in where?
in what line?
Thanks for your answer
i tried
but he show me this error
Unexpected insert a semicolon in the end ;
Thanks for your answer :( i think that this code is wrong :( i should write the code again? you know other code for "AI enemies" different of this code?
Your answer
Follow this Question
Related Questions
Input key Conversion Query? 0 Answers
Returning variables in a plugin 1 Answer
Change animation after double tapping arrow 0 Answers
Suggestions about creating a big map 1 Answer