- Home /
Rotating a line renderer
I want to make a really abstract minimap for my racing game, which consists only of a line for the track (the line renderer) and a dot/s for the car/s. My problem is that I don't know how to set the main camera as pivot point of the map so that the map is always in the top right corner of the screen and how to rotate the whole line when the camera rotates.
Any ideas?
Answer by Luci85 · Apr 26, 2012 at 11:32 AM
Ok, found the answer, you loop through the whole line and rotate every point with the rotation matrix. If someone needs the code:
var PIDiv180 = Mathf.PI/180;
function rotate(pivotPoint:Vector3, pointToRotate:Vector3, angle:float)
{
var result:Vector2;
var Nx = (pointToRotate.x - pivotPoint.x);
var Ny = (pointToRotate.z - pivotPoint.z);
angle = -angle * PIDiv180;
result = Vector2(Mathf.Cos(angle) * Nx - Mathf.Sin(angle) * Ny + pivotPoint.x, Mathf.Sin(angle) * Nx + Mathf.Cos(angle) * Ny + pivotPoint.z);
return result;
}
Depends on what you want to do with the vector3. Simplest method would be change the result to vector3 and initialise the y-coordinate with 0. Like this: var result:Vector3; ... result = Vector3($$anonymous$$athf.Cos(angle) * Nx - $$anonymous$$athf.Sin(angle) * Ny + pivotPoint.x, 0, $$anonymous$$athf.Sin(angle) * Nx + $$anonymous$$athf.Cos(angle) * Ny + pivotPoint.z);
Your answer
Follow this Question
Related Questions
Minimap arrows 0 Answers
Is it possible to fit a linerenderer turn in the rotation of the parent object? 0 Answers
Minimap rotation 2 Answers