- Home /
Question by
HarisKap · Jan 28, 2013 at 01:48 PM ·
raycastenemypath-findingavoid
top down game,enemies align next to each other
Hello,i am making a top down view game.
My enemies are spawning from different spawn points,seek for the player and they stop in an attack distance,where i play the attack animation.what i want to do is when they are next to my player i dont want them to push each other but align one next to each other like a circle.
my function is the following:
function MoveAndRotate(targetPosition:Vector3) {
var thisPosition:Vector3 = transform.position;
targetPosition = Vector3(targetPosition.x,thisPosition.y,targetPosition.z);
transform.position = Vector3.SmoothDamp(thisPosition,targetPosition,velocity,smoothTime,maxSpeed);
var toRotation:Quaternion;
if (targetPosition - thisPosition != Vector3.zero) {
toRotation = Quaternion.LookRotation(targetPosition - thisPosition);
}
transform.rotation = Quaternion.RotateTowards(transform.rotation,toRotation,maxRotationSpeed);
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position,forward,hit, 5))
{
if(hit.collider.tag == "Enemy")
{
transform.Rotate(Vector3.up * 30);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Hit enemy life with raycast 1 Answer
2d raycast enemy detection problem. 0 Answers
How to Stop Enemy "Shooting Through A Wall" 1 Answer
spherecast wont work 2 Answers