- Home /
Circling around a target while maintaining direction of facing
This is a code i did to make a circumambulation test around an object, void Start () {
transform.LookAt (target);
}
void Update () {
dist = Vector3.Distance (target.position,transform.position);
var step = speed*Time.deltaTime;
if(Vector3.Distance (target.position,transform.position)>10){
transform.position=Vector3.MoveTowards (transform.position,target.position,step);
}else if(Vector3.Distance (target.position,transform.position)<10){
transform.RotateAround (target.position,Vector3.up,degrees*Time.deltaTime);
}
}
The code above tells that the character will face the target and move towards it. Then, after a certain distance from the target, the character will rotate around the target at constant position and degree. This will make the character facing the target while circling the target. The thing is I want to make the character circling the target to the right.
-after a certain distance from the target,the character will change direction facing towards right while circling the target
-keep the target at the left of the character.
I've been trying to use Quaternion.LookRotation(Vector3.right,Vector3.up) and it locks the look rotation to the right of the world coordinate. Any help would be appreciated.
Your description is confusing. A drawing might help. Given your description, you probably want:
Quaternion.LookRotation(transform.right);
This is the local right of the character rather than global right.