- Home /
Question by
ThisIsMyAccount · Dec 21, 2016 at 07:32 AM ·
2drotationmeshmeshrenderermeshfilter
Why is my script constructed mesh rotating the wrong way
Hi everyone
I have a script which constructs a mesh that is supposed to represent a 2d field of view similar to the soliton radar in metal gear solid. However when I rotate during gameplay it rotates the opposite direction I'd like it to. How could I fix this?
This is the code
function DirectionForAngle(angleNumber : float, isGlobal : boolean){
if(!isGlobal){// if local
angleNumber -= transform.eulerAngles.z;
}return Vector2(Mathf.Sin(angleNumber * Mathf.Deg2Rad),Mathf.Cos(angleNumber * Mathf.Deg2Rad));
}
function DrawFieldOfViewMesh(){
var stepCount : int = Mathf.RoundToInt(losViewAngle * meshResolution);
var stepAngleSize : float = losViewAngle / stepCount;
var viewPoints = List.<Vector2> ();
var oldViewCast : ViewCastInfo = new ViewCastInfo();
for(var i : int = 0;i<= stepCount; i++){
var angle : float = transform.eulerAngles.z - losViewAngle / 2 + stepAngleSize * i; // change y maybe?
Debug.DrawLine(transform.position, transform.position + DirectionForAngle(angle,false) * losViewRadius, Color.red);
var newViewCast : ViewCastInfo = ViewCast(angle);
if( i > 0){
var thresholdExceeded : boolean = Mathf.Abs (oldViewCast.dst - newViewCast.dst) > edgeDstThreshold;
if(oldViewCast.hit!= newViewCast.hit || (oldViewCast.hit && newViewCast.hit && thresholdExceeded)){
var edge : EdgeInfo = FindEdge(oldViewCast,newViewCast);
if(edge.pointA!=Vector2.zero){
viewPoints.Add(edge.pointA);
}
if(edge.pointB!=Vector2.zero){
viewPoints.Add(edge.pointB);
}
}
}
viewPoints.Add(newViewCast.point);
oldViewCast = newViewCast;
}
var vertexCount : int = viewPoints.Count + 1;
var vertices : Vector3[] = new Vector3[vertexCount];
var triangles = new int[((vertexCount-2) *3)];
vertices[0] = Vector3.zero;
for( i = 0;i<vertexCount-1;i++){
vertices[i+1] = transform.InverseTransformPoint(viewPoints[i]);
if(i<vertexCount-2){
triangles[i*3] = 0;
triangles[i*3+1] = i+1;
triangles[i*3+2] = i+2;
}
}
fovMesh.Clear();
fovMesh.vertices = vertices;
fovMesh.triangles = triangles;
fovMesh.RecalculateNormals();
fovMesh.RecalculateBounds();
}
Not very good at Vector maths admittedly and I've been following from a tutorial so I only half understand what I've even written in the first place. Any and all help appreciated. Thanks in advance!
Comment
FIXED IT
I JUST CHANGED transform.eulerangles.z to -transform.eulerangles.z