Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThisIsMyAccount · Dec 21, 2016 at 05:28 PM 0
Share

FIXED IT

I JUST CHANGED transform.eulerangles.z to -transform.eulerangles.z

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Im reading a .obj file and converting it to a mesh (doesnt work) 0 Answers

2d custom mesh triangulator problem 1 Answer

Can you manually set the layer order for triangles inside a mesh? 2 Answers

Submeshs doesn't combine with materials 1 Answer

Color not being applied properly to mesh 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges