- Home /
Adding gravity to NPC, such as an enemy or animal?
When I place my enemy into the scene and play the enemy follows be by floating around and doesn't stick to the ground. Here is my code:
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 TheEnemyDamage = 40;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
private var MoveDirection : Vector3 = Vector3.zero;
function Start()
{
attackTime = Time.time;
}
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if (Distance < attackRange)
{
attack();
}
else
if (Distance < chaseRange)
{
chase();
}
}
That is not all of it but can someone tell me if I should include the whole script.
I also tried adding a rigid body to it but that wont allow the enemy to move at all.
I need to see the rest of the script, or at least the function where you use CharacterController.$$anonymous$$ove() or CharacterController.Simple$$anonymous$$ove(). Note if you look at the reference pages for $$anonymous$$ove() or Simple$$anonymous$$ove() (whichever one you are using), the example scripts implement gravity.
Your answer
Follow this Question
Related Questions
How to freeze enemy movement when Hurt/enemy Damage? 1 Answer
Enemy Rigidbody Not Responding to Gravity 1 Answer
npc collider 1 Answer