# Vector3 to rotation.z but how ???

Hello,
well i’m working on a direction display.
i get my Vector3 where the goal is but i can not convert it to rotate a grafic on screen that point’s to the GO where i got the Vector3 from…
here is my code:

``````function UpdateAttitude (playerTransform : Transform) {
var enemyPos : Vector3 = finish.Target() - playerTransform.position;;
enemyPos.y = 0.0;
enemyPos.Normalize();

var screenVec : Vector2 = new Vector2(enemyPos.x, enemyPos.z);
Entf = enemyPos;

var DirectionTransform : Transform = Direction.client.transform;
DirectionTransform.rotation = Quaternion.Euler (0,0,enemyPos.z);
Direction.Transform(); // here i apply the rotation to my grafic
}
``````

playerTransform = my Position … got updated
finish.Target() = where i want to go… Vector3

thank you !!!
kerstin

Ahoy Muckel,

To get the Z coordinates to get your player there, or the enemy position, i used this, to send something to a certain point, which contains the z.

``````if (Input.GetButtonDown("Fire1"))
{
mouseButton1DownPoint = Input.mousePosition;

var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
}
``````

Hope it helped dont have time to explain everything about it.

thanxxx but that was not what i wanted so far…
here is where i’m stuck now…

``````function UpdateAttitude (playerTransform : Transform) {

var v : Vector3  = finish.Target() - playerTransform.transform.position;
v.y = 0.0;
//if (v.sqrMagnitude < 0.1) return;
var DirectionTransform : Transform = Direction.client.transform;
DirectionTransform.transform.rotation = Quaternion.LookRotation(v) * Quaternion.Inverse(playerTransform.transform.rotation);
//DirectionTransform.LookAt(DirectionTransform.position - v);
//DirectionTransform.Rotate(Vector3.right, -90, Space.Self);
Direction.Transform();
``````

it works but it also rotates on the wrong axis… i only need it on z

thank you

kerstin

Quaternion.LookRotation has an optional second parameter that specifies the upward direction. If you pass the player’s up direction, you should get the result you want:-

``````...Quaternion.LookRotation(v, player.up)...
``````

Hello,
thanxx for the help but that doesn’t work…
my Arrow graphic is still rotating in 3D Space …

``````      var v : Vector3  = finish.Target() - playerTransform.transform.position;
v.y = 0.0;
//if (v.sqrMagnitude < 0.1) return;
var DirectionTransform : Transform = Direction.client.transform;
DirectionTransform.transform.rotation = Quaternion.LookRotation(v, playerTransform.up) * Quaternion.Inverse(playerTransform.transform.rotation);
Direction.Transform();
``````

… well here is my working solution so far…
maybe there is some room to optimize this…

``````  var targetDir = finish.Target() - playerTransform.position;
var forwardx = playerTransform.forward;
var angle = -Vector3.Angle ( targetDir, forwardx);
var DirectionTransform : Transform = Direction.client.transform;
DirectionTransform.rotation = Quaternion.Euler (0,0,angle);
``````

kerstin