Rotation results x value only positive.

The following class is ment to combine 2 planes into 1 arrow that is variavble in size, while the head keeps it size.

The constructor technically works, but for some reason the arrow isn´t point correctly in x direction, which means negative x values are returned as positive. I have been looking at this code for hours now, and might be just missing something:

public class arrowGraphics

{

GameObject pointer;
GameObject body;

public Vector3 From;
public Vector3 To;
float length;
// Use this for initialization
public arrowGraphics (Vector3 f, Vector3 t)
{
	From = f;
	To = t;
	
	pointer = (GameObject)Object.Instantiate (Resources.Load ("arrowPointer"));
	body = (GameObject)Object.Instantiate (Resources.Load ("arrowBody"));
	length = Vector3.Distance (From, To);
	
	
	Vector3 tempPos0 = new Vector3 (0, (float)0.1, (float)-length);
	float scaleOnBodyZ = (float)(length - 2.5) / 5; 

scales the body to the distance between from and to

	Vector3 tempPos1 = new Vector3 (0, (float)0.1, (float)-(2.5 * scaleOnBodyZ));
	float rot = Vector3.Angle ((To - From), new Vector3 (0, 0, -length));

is ment to determine the angle between the direction of the arrow and the direction of the mesh arrow

	pointer.transform.position = tempPos0;
	if (length > 2.5) {
		body.transform.position = tempPos1;
		body.transform.localScale = new Vector3 ((float)body.transform.localScale.x, (float)body.transform.localScale.y, (float)body.transform.localScale.z * scaleOnBodyZ);
	} else {
		body.transform.position = new Vector3(0, -10, 0);
	}

puzzles the two mehses together

	pointer.transform.RotateAround (Vector3.zero, Vector3.up, rot);
	body.transform.RotateAround (Vector3.zero, Vector3.up, rot);

then rotates around 0,0,0 by the calculated degress

	pointer.transform.position = pointer.transform.position + From;
	body.transform.position = body.transform.position + From;
}

moves the rotated meshs into place.

whole thing works for the most part, except for the x not to negative, even thought the size of x is correct.

Some explaination: The whole rotation is doen by moving the thing to 0,0,0 to perform a save rotation/scaling and then move it with the right angles to where it belongs.

For someone might wonder, if the difference between from and to is shorter than the head of the arrow, the body is moved no nomansland. could be destroyed as well, but I´m not sure how to deal with changing existing arrows yet, so I kept it. However, the should be somewher in the first half of the constructor.

any help would be apreciated.

Vector3.Angle is just a dot product, and doesn’t give a direction: 30 degrees clock and counter clockwise (or up, in 3D space) all give 30. Could throw in a handWritten Left/Right check off your forward Vector (if your starting lines are always up, just check x>0.)

I find quaternions easier when you want real angles. Could compute your angle as a Quat:

Quaternion angle=Quaternion.FromToRotation(Vector3.forward*-length, To - From);

You’d then apply it with: transform.rotation = angle*transform.rotation (or else rot*angle – the order matters.)