How to take the camera counter rotation on Unity 5

Asked

Viewed 200 times

3

I wonder how I can move an object in the opposite direction of the camera.

Example: When I move the camera to the right in any position (0.30.0), the object moves in the opposite direction (0.-30.0) to the left.

  • You want to do this programmatically whenever something moves the camera?

  • What you use to move, you just add in Transform.position ?

  • that, whenever the camera moves, the prefabs tb will move only in the opposite direction.

  • I’m doing like this var rot = Cardboard.SDK.HeadPose.Orientation; transform.rotation = Quaternion.Euler (Vector3.down *rot.eulerAngles.y);

  • But when you instantiate Prefab, it loses the rotation it had and gets on top of each other

2 answers

2

I got it like this:

void Update ()
{
    rot = Cardboard.SDK.HeadPose.Orientation;
    transform.localEulerAngles = (Vector3.down * rot.eulerAngles.y);
}

Turning around the camera.

0

You must , first access the Camera. It has innumerable forms, judging that you already know how to do it ,you can do the following :

 transform.rotation = Quaternion.Inverse(ObjCamera.transform.rotation);

For more information about the Quaternion Class(Rotation) : Quaternion

  • Thanks Rodrigo, I used this- Transform.rotation = Quaternion.Euler (Vector3.down * rot.eulerAngles.y); but I’m instantiating a Prefab with another rotation, and the movement is only applying to a single Prefab

  • you want all prefabs to move when the camera moves?

  • That, the prefabs then around the camera, making a circle, and I want everyone to turn in the opposite direction that the camera is.

  • Yes, but they must rotate around themselves, or around the camera?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.