There are two things I’m not grasping today that are probably very simple!
1. How can you rotate a vector3?
For instance, I have captured an object’s rigidbody.velocity, and I want to find the direction that’s directly to the left of that motion. So I want to rotate the velocity vector 90 degrees around Y and get another vector3 as the result. I can probably use a bunch of atans etc. but usually when I catch myself doing that it means I’m overlooking that Unity has a simpler way
2. On page 20 of the very helfpul Scripting Tutorial PDF, the script contains the following line:
private var activeWayPoint : WayPoint;
What is being done here? Normally after the colon I would expect something like “Transform” that’s in the Unity manual. “WayPoint” is not. So what, then, is WayPoint in this line?
I know what waypoints are used for in the tutorial, but I don’t get that line of code. Something similar happens with : Score in the other tutorial. I think I need the beginner’s paragraph on what you can and can’t do with that colon!
Your answer to rotating vectors in Unity is Quaternion. You acheive the rotated vector by multiplying a Quaternion containing the desired rotation with the original vector:
var rotation=Quaternion.EulerAngles(10 * Mathf.Deg2Rad, 10 * Mathf.Deg2Rad, 15 * Mathf.Deg2Rad);
var rotatedVector = rotation * originalVector;
But to roate 90 degrees around an axis is even easier - use the cross product:
var rotatedVector = Vector3.Cross(originalVector, Vector3.up);
Ad. 2:
WayPoint is probably a user defined script. For it to work, the project must contain a script called WayPoint.js.
You can put any type name after the colon. ie. internal types (int, float, string, …), Unity Engine classes (GameObject, Transform, Vector3, Quaternion, …), .Net framework classes (Hashtable, ArrayList, …) and classes and scripts included in the project (MyJavaScript1, MyJavaScript2, WayPoint, whatever you name them)
Thanks–I understand with scripts, but when you say “classes and scripts included in the project”… are there other user-created classes besides scripts, that would be referenced in this way?