- Home /
LookRotation or euler angle object rotation towards
I have a project That should draw vectors in 3d space and draw them as actual force in space. Origin is the Vectors default position. I have Vector 3 information about the force, for example new Vector3(213,243,11). I am rescailing vectorGameobject according to vectors magnitude, but am haveing trouble with pointing the vector in right direction, that is the direction of the force. I have tryed this: vectorsLeft[i].transform.localEulerAngles = new Vector3((float)leftCycleAnimationData.Fy[i], (float)leftCycleAnimationData.Fz[i], (float)leftCycleAnimationData.Fx[i]) ; vectorsRight[i].transform.localEulerAngles = new Vector3((float)rightCycleAnimationData.Fy[i], (float)rightCycleAnimationData.Fz[i], (float)rightCycleAnimationData.Fx[i]);
but it draws vectors in exactly oposite direction. Is there a way to revert this direction to -direction?
Then I tryed making a test scene for other rotate functions:
written this code:
public class RotationController : MonoBehaviour {
public GameObject[] cilinders;
public GameObject tagetObject;
void Start () {
}
public void rotator()
{
for (int i = 0; i < cilinders.Length; i++)
{
Vector3 target = tagetObject.transform.position;
Vector3 direction = (target - cilinders[i].transform.position) ;
Quaternion rotation = Quaternion.LookRotation(direction/*,Vector3.up*/);
cilinders[i].transform.rotation = rotation;
Debug.Log("direction " + direction.x + "," + direction.y + "," + direction.z + ",");
Debug.Log("rotation" + rotation.x + "," + rotation.y + "," + rotation.z + "," + rotation.w);
Debug.Log("cilinders[i].transform.rotation" + cilinders[i].transform.rotation.x + "," + cilinders[i].transform.rotation.y + "," + cilinders[i].transform.rotation.z);
}
}
}
and got a result:(cannot load more pics): stickc(vectors )seem to be perpendicular to the cube, not pointing to the cube. Any sugestions??
thx
Answer by fashrista · Nov 19, 2017 at 04:31 PM
ps.: thats the other picture