# How to stop a unit from rotation once it gets to designated position?

Hello guys, I’m having troubles… With the script I have so far, when the unit reaches its designated position, it still keeps rotation itself standstill…

This is the code:

``````if (target != this.transform.position)
{
// find the vector pointing from our poisiton to the target
directionToMove = (target - this.transform.position).normalized;
// create the rotation we need to be in to look at the target
lookRotation = Quaternion.LookRotation(directionToMove);
// rotate us over time
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
this.transform.position += this.transform.forward * moveSpeed * Time.deltaTime;

isMoving = true;
}
``````

Any ideas? Thanks!

lookRotation = Quanternion.LookRotation(directionToMove - transform.forward)

``````mark as answered and have a nice day :)
``````

``````#pragma strict

var distance : float;
var target : Transform;
var lookAtDistance : int = 15.0;
var attackRange : int = 10.0;
var standOffDistance : float = 2;
var moveSpeed : int = 5.0;
var damping : int = 6.0;

function Update ()
{
distance = Vector3.Distance(target.position, transform.position);

if(distance < lookAtDistance)
{
lookAt ();
}
if((distance < attackRange) && (distance > standOffDistance))
{
attack ();
}
}

function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}

function attack ()
{
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
``````