- Home /
Can someone explain how this piece of code from third person prefab works ?
// calculate camera relative direction to move:
m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
m_Move = v*m_CamForward + h*m_Cam.right;
m_CamForward and m_Move are vector3
v and h are GetAxis inputs
m_Cam is transform of the main camera
The code is supposed to calculate the movement direction of the character relative to the camera but I'm struggling to understand what Vector3.Scale does and why it is used. It says it multiplies the components of two vectors but why do you want to multiply m_Cam.forward with (1,0,1) ? What happens when you multiply (0,0,1) with (1,0,1) ? And why normalized, does it also multiply the magnitudes ? Is there an easy way to visualise these vectors so I can understand a bit better ? Or is there a good tutorial to get used to working with vectors in unity ?
Your answer
Follow this Question
Related Questions
Point game object to another only on the Local X Axis 0 Answers
Using Vector3 with multiple directions 1 Answer
How to apply equal force back to player when colliding with a wall? 2 Answers
Object's vectors are not moving with the object, what did i do wrong? 1 Answer
Boxcast vs Raycast Oddities 1 Answer