I am trying to make an object translate to a given position using a new Vector3 position
and also rotate to a new quaternion. The object translates properly, but I’m not sure how
to make it rotate properly using the 3 axis rotation numbers (x, y, z). What is the w factor
and how do I use them properly to make this object appear in the proper rotation?
The two lines that I use to move and rotate the object are:
gameObject.transform.localPosition = new Vector3(_location2posX, _location2posY, _location2posZ);
gameObject.transform.localRotation = new Quaternion(_location2rotX, _location2rotY, _location2rotZ, 1);
When I check the object in the inspector, it has moved to the correct vicinity, but all of the rotation numbers are a bit
off. Again, I don’t know what the w factor is or how to use it to assign the correct destination rotation.
A quaternion is build from an axis (xyz) and the rotation (w) about that axis.
You can also set a quaternion to Euler angles:
Quaternion q = Quaternion.Euler( new Vector3( rotX, rotY, rotZ ) );
Im sure the help used to say something like, if you don’t understand quaternions, don’t try create them… anyhoo
Use Euler as mentioned above, however, dont use the overload that creates an extra un-needed vector…
Quaternion q = Quaternion.Euler( rotX, rotY, rotZ );
Thank you.
When my player arrives at their new destination alongside that object, the camera is still aiming at their last pointed to position.
I would like to rotate the camera to a new aiming point, but I don’t know how to accomplish that either. This is the statement
that I thought would work:
GameObject.Find("Main Camera").gameObject.transform.localRotation = Quaternion.Euler(4, 0, 0);
However, it does nothing.
Camera.main.transform.LookAt( put your player transform here… )
Ok, I don’t understand how that works.
I put a Vector3 into the LookAt call and it doesn’t face toward it.
The Vector3 is the transform of an object that I want the camera to be looking at.
I got that transform from the inspector and made a Vector3 variable and called it like this:
Camera.main.transform.LookAt(_fountain2pos);
not quite.
A transform is a transform, not a vector3. transform is a property of a gameobject
transform.position is a vector3 which is a property of a transform
Because my first person camera is attached to my mouse, I have to move the mouse
and not just rotate the camera to make the player look where I want. Input.mousePosition
is read only, so can you tell me how to make the mouse cursor move to the spot that the
player is looking after using LookAt() on them ?
Basically, I just want the player to transport to another location and I want to control what
direction they are facing when they get there. My controller is FPS type.