- Home /
Question by
potu1304 · Nov 02, 2013 at 12:24 PM ·
collideraitransform.position
Collider for transform.position?
Hello!
I have a problem. I have added to my simple EnemeyAI a simple movement, here is the script: 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
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
But how can I say that my enemy is not walkin through walls anymore?
Comment
Best Answer
Answer by Zaeran · Nov 02, 2013 at 01:25 PM
Simplest way would be to raycast from the enemy to a certain distance in front of it. If something is hit by the raycast, don't move forward.
if(!Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), 1){
//move forward
}