Home > Blockchain >  how can i keep the gameobject only move in 90 degree withe another
how can i keep the gameobject only move in 90 degree withe another

Time:04-15

enter image description here

like this, how can I make the white one only move the 90-degree path with the red one.

enter image description here

CodePudding user response:

I hope this is somewhat what you are searching for.

var radius = Vector3.Distance(redObject.transform.position, whiteObject.transform.position) ;
Vector3 direction = Quaternion.Euler(0, angle, 0) * Vector3.right;
var newPosition = redObject.transform.position   direction * radius;
whiteObject.transform.position = newPosition;

Where you need to make your own direction and replace Vector.right with up or forward.

  • Related