- Home /
Rotate objects face to camera
Hi all, I'm new here, and my english is not very good.
I am creating a generator molecules.
When I add a triple molecule want to face the cylinders always stay ahead of the camera.
Attached a picture!
I'm rotating the molecules with ITween, like this:
switch (number) {
case 1:
if (count == 0)
iTween.RotateTo (connection, Vector3 (0.0, 0,2.0);
break;
case 2:
if (count == 0) {
iTween.RotateTo (connection, Vector3 (0.0, 0,2.0);
} else if (count == 1) {
iTween.RotateTo (connection, Vector3 (180.0, 0,2.0);
}
break;
And I have a function that updates the rotation of the double and triple molecules.
With 2 molecules already got an interesting result. But with 3 onwards was not good.
Attached project too. PROJECT DOWNLOAD
Thank you very much.
I try this:
var targetAngle : float = Vector3.Angle( Camera.main.transform.position, temp.transform.position );
currentAngle = $$anonymous$$athf.$$anonymous$$oveTowards(curAngle, targetAngle, 3 * Time.deltaTime);
temp.transform.RotateAround (moleculaCentral.transform.position, Vector3.forward, curAngle);
But dont work! :(
Answer by zharik86 · Dec 27, 2013 at 01:17 PM
Why not to use usual transform.Rotate ()? Place everything your object in one main (some kind of container). That to make it, create empty GameObject. Its position (0, 0, 0), rotation (0, 0, 0), scale (1, 1, 1). After it is possible to rotate the created container, at the same time rotating cylinders and spheres.
This script is almost run. Only it has some angles that is crazy! rs.rs.rs
var targetAngle : float = Vector3.Angle( Camera.main.transform.position, temp.transform.position );
var cross:Vector3 = Vector3.Cross(Camera.main.transform.position, temp.transform.position);
if (cross.z > 0) targetAngle = -(targetAngle);
curAngle = $$anonymous$$athf.$$anonymous$$oveTowards(curAngle, targetAngle, speed * Time.deltaTime);
temp.transform.eulerAngles = Vector3(0, 0, curAngle-45);
At a specific angle it rotates the opposite angle to reach the destination.
In this script the rotation does not respond well in some angles. See the video: http://www.youtube.com/watch?v=Vpp$$anonymous$$BlodLdc
@$$anonymous$$arcosprod Do you want to rotate the camera round object or object?