Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Smots · Mar 17, 2014 at 10:30 PM · unity 2dmeshrenderercollider 2dpolygon collider 2dunity 4.3

Unity 4.3, generate 2d mesh

Hello everyone.

For a top down 2D simulation I'm trying to create characters with a displayed FOV cone. I've thought up the math and everything, but the problem I'm facing is implementing this in the 2D mode.

It would be great to create a filled version of the meshCollider2d as a meshfilter2d (which doesn't exist). I have 2 reasons for wanting to do this in the 2D mode:

  1. I want to use 2D line casting against 2D colliders on sprites.

  2. I want to display the dynamic FOV in between the floor and whatever is above it as a semi-transparent overlay.

I've been googling for over an hour trying to find a matching solution, but nothing turns up for the new 2D mode.

Is this possible or is this outside the bounds of what the 2d mode made for?

Comment
Add comment · Show 2
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 Adamcbrz · Mar 18, 2014 at 03:51 AM 0
Share

I am not sure I understand your goal here. A mesh filter has a mesh it is irrelevant to the filter if it is 2D or 3D. I think I am misunderstanding your objective.

avatar image Smots · Mar 18, 2014 at 07:09 AM 0
Share

Sorry about the use of meshfilter and meshcollider.

Let me rephrase. I want to create a dynamic mesh (from code). A mesh requires a mesh renderer which uses the Z-axis for depth display (3D) A sprite uses a quad wich uses a depth parameter in the inspector for depth display (2D) What I'm trying to achieve is displaying a mesh in between 2 sprites.

Example: 0: floor sprite 1: FOV mesh 2: table sprite

FOV mesh will display above the table. How to set a 2D depth parameter to it?

Second point is... Is it bad practice to place a 2D polygon collider and a $$anonymous$$esh rendered (3D) on the same object?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Adamcbrz · Mar 18, 2014 at 12:52 PM

All of this is rendered down to opengl so unless they are creating 3d meshes either way. So unity is doing some more advanced stuff under the hood to handle the depth. If you want to interlace 3d and 2d you need to set all the sprite depth's to zero and use z-position for depth instead. This doesn't effect collision because 2D collision ignores z-position. Second question: yes you can use any of the 2d colliders with a 3d mesh renderer.

Comment
Add comment · Share
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
0

Answer by Smots · Mar 19, 2014 at 10:28 PM

Thanks for the information Adamcbrz. I did find another way to fix the depth issue. A youtube video on unity 2d displayed a sprite based game with a 3d mechanical arm/crane on the background with a parallax background behind that, so I did decide to google some more, found this after another few hours: http://forum.unity3d.com/threads/212006-Drawing-order-of-Meshes-and-Sprites

In short, all I needed to do was place this in the Start() function

 renderer.sortingOrder = 1;

I did encounter a problem when updating the MeshFilter and the PolygonCollider2D in the same run (Tried in both Update and FixedUpdate). The MeshRenderer started to flicker. Disabling the PolygonCollider2D by unchecking it fixed the flickering. Ps, I noticed the PolygonCollider2D flickering in the scene view.

Am I right to assume then that the PolygonCollider2D and the MeshRenderer don't mix?

I used the following at the end of my MeshFilter update:

 GetComponent(MeshFilter).mesh = mesh;

And at the end of my PolygonCollider2D update:

 var polyColl2D : PolygonCollider2D = gameObject.GetComponent("PolygonCollider2D");
 polyColl2D.SetPath(0, points);


Comment
Add comment · Share
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

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't get my objects to collide 1 Answer

gameObject with 2 colliders with different layerMasks ? 1 Answer

Joint2D Tutorials 1 Answer

Perform an action after Animator is finished 1 Answer

Unity 2D: sprite's rigidbody weight/rotation 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