Hey people,
Currently i,m working on a fast paced action RPG and am stuck on the AI of the enemy.
Whenever i enter it’s "aggro"range it automatically comes at me ( as it should) but then
then the following happens depending on which imported mesh i have active:
-
Old enemy model with attached script: Wont find / play walking animation as soon as it starts moving( hasnt been propperly imported due to it’s pivotpoint being backwards so i placed it in a gameobject to fix that)
-
new enemy model with attached script: Does play animation but first jumps away ( half through the floor) and then comes closer. when it’s at a closer range ( yet further than the other model) it starts spinning around the character in all 3 dimensions(old model only spinned in 2 dimensions and litterally around the character). I’ve tried adding a rigid body to it but it instantly
Decided to fall through the floor on me. Ofc the ground has a mesh collider on it so it’s rather strange the enemy mesh doesnt recognize it.
Could anyone have a look at the code and see what i’ve done wrong as i preffer to use the newer model since i,m going to have to clean up/edit and add some more animations at a later stage on the enemy.
P.s the only small edit i’ve made when putting the code on the newer model is that i could get rid of the var on line 38 and could put an animation.play(“Running”)
var target : Transform; //the enemy’s target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
//var myTransform:Transform; //current transform data of this enemy
static var isTriggered = false;
static var Playerhitbox = false;
function Awake()
{
//myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
//if isTriggered = true;
target = GameObject.FindWithTag(“Player”).transform; //target the player
}
function Update ()
{
if(isTriggered)
{
//rotate to look at the player
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position-transform.position), rotationSpeed*Time.deltaTime);
//move towards the player
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
var Enemy_animation = GameObject.Find(“Enemy_bugged”);;
//var Enemy_animation = getComponent(“Enemy_bugged”);; tried wouldnt work
// Enemy_animation = GameObject.FindWithTag(“Enemy”) tried wouldnt work
// Re-imported Object flipped in max and got even stranger bugs…
// next line continueation of what should be working above this.
//Enemy_animation.animation.Play(“Running”, PlayMode.StopAll);
}
//if(Playerhitbox) enemy should stop and attack
}
Thanks in advanced
Digi