# How to make an enemy move and attack with animation

I’ve just started using unity, and I don’t have much animation skill. So I’m wondering if it is possible to get a model to move without being animated and when it hits the player it would cause damage to that player. I understand this may sound a little strange but what I have in mind is the enemy gliding along the environment rather than a walk cycle.

Is this possible? Help greatly appreciated.

Here is a simple script i use a lot for my Enemies you can try it if you’d like.

`var range : float;
var speed : float;
var damping : float;
var closest : GameObject;
//var Running : GameObject;
//var Fighting : GameObject;
//var Idle : GameObject;
var ClosestDistance : int;

InvokeRepeating(“FindClosestEnemy”, 2, 0.3);

``````// Print the name of the closest enemy
print(FindClosestEnemy().name);

// Find the name of the closest enemy
function FindClosestEnemy () : GameObject {

// Find all game objects with tag Enemy
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Player");
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and find the closest one
for (var go : GameObject in gos)  {
var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
distance = curDistance;

}
}
return closest;
}
``````

function Update ()
{
range = Vector3.Distance(closest.transform.position, transform.position);
var rotation = Quaternion.LookRotation(closest.transform.position - transform.position);

``````if (range > ClosestDistance)
{
//Running.SetActive(true);
//Fighting.SetActive(false);
transform.Translate(Vector3.forward*speed);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
if (range < ClosestDistance)
{
//Fighting.SetActive(true);
//Running.SetActive(false);
}
``````

}
`

the script above will cause the object to follow the object it tagged (player) as long as there is an object in the game tagged as player. keep in mind this script reqiures you have a collider and rigidbody on your enemy.

for the players health script use this.

``````var curHealth : int = 50; //set current health
var maxHealth : int = 100; //set max  health
var projectile : GameObject;

function OnTriggerEnter(Col : Collider)
{
if (Col.gameObject.tag=="Enemy"){
curHealth = curHealth - 50;
}
}

function Update ()
{
if(curHealth <= 0)
{
Instantiate(projectile, transform.position, transform.rotation);
Destroy (gameObject);
}
}
``````

the script above takes away 50 health when the object tagged “Enemy” collides with it once the player dies an explosion or whatever of your choosing is Instantiate and the player is destroyed.

Yeah, just change it’s transform’s position. It’ll move without the animation. Put the movement in `Update`.