- Home /
Rotate a vector WITH transform.
Hello, I am working on a top down game in which the player is able to move in eight directions, forward, back, left, right and diagonals. The direction is established through vector3 and is a rigidbody force. This is controlled by WASD. I want the arrow keys to control the camera angle in 90 degree increments. However the vector3 stays the same, so that pressing up would move the character right according to the newly rotated camera. How would I go about rotating the vector?
Just a question to help me understand the scene. If you were to go into your scene, change the rotation of your camera to 90, then press start, would you get the control scheme you are looking for?
No. Sorry, I forgot to elucidate that it's not EXACTLY top down, the camera looks down on the character at an angle. The camera is technically slightly behind and above the character.
Your name fits your question perfectly. It's just an "abstract fragment"...
If it's a top down game it sounds extremly strange if you talk about changing "the angle". What angle? around which axis? Also what "vectors" do you actually talk about? How about showing the relevant code, a screenshot or a conceptual drawing of you problem?
The character is being transformed, rotated. So that this becomes this .
Relelvent code fragment.
if (Input.GetButtonDown("rotate"))
{
transform.Rotate(Vector3.up * (90 * angleAxis));
}
Sorry for the confusion amigos. By top down I really mean 45 degree angle down.
Sure. You started a conversation with me on the forums. I think it would be best to continue this there so we don't keep bumping this question
Answer by Superrodan · Jan 21, 2015 at 07:48 AM
What you want to do is use "transform.forward" in your code instead of Vector3.forward.
Vector3.forward is in world space and always goes in one direction based on world space. "transform.forward" goes forward in the gameObject's local space.