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 junglejapes · Dec 11, 2013 at 11:57 PM · meshspriteslicecut

How to slice a sprite realime C#

Hello there, in my 2D game I want to have my characters dying effect to be being cut in half (random degree 0-359 and then straight across).

I am just wondering how to get this accomplished. I do not care to purchase any assets I would like to do this from scratch. I'm a pretty good programmer in C# and JS but I cannot seem to find any functions in the script reference that would apply.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kiloblargh · Dec 12, 2013 at 12:08 AM

I haven't actually used the 2D sprite features yet (I'm still too busy with the 3d game I've been working on since before the 2D stuff was added) but the approach I would take is to use a shader that takes an alpha mask texture, duplicate the object into two copies in the same spot, and apply a half-black-and-half-white mask texture to one, invert the texture and apply it to the other.

If you don't really need it to cut in a totally random direction, you could create as many slice-masks as you like and pick one from an array at random. (This approach would make a torn-looking, anti-aliased edge much easier to achieve.) If you feel you do, you will have to use Texture2d.SetPixels and test whether each pixel it is above or below a line with a random slope passing through the center, using your mighty math powers... I could work out the code to do that if it were my project but don't have the spare time right now to do it for you, so if you're a pretty good programmer I'm sure you can figure it out.

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 EX_Darius · Dec 12, 2013 at 12:05 AM

As far as I know you would need to create 2 seporate gameobjects and child them into the empty main character object, then moving them apart if your character dies.

However Ive seen some shaders that are able to do what you described without having to create multiple objects etc.

I suggest you take a look in the shaders part of the asset store.

Comment
Add comment · Show 2 · 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 junglejapes · Dec 12, 2013 at 12:15 AM 0
Share

Thanks for the reply, I will go ahead and take a look at the shaders in the asset store. I actually had no idea it was even possible to have this effect through shaders. Doesn't make a lick of sense to me. Do you think you could give me the name of one? It seems the asset store on mac is a little bit broken when trying to browse.

avatar image EX_Darius · Dec 12, 2013 at 12:19 AM 0
Share

I think the shader for 3d models was called "Fragmentum" , im not entirely sure if this will work for sprites but its worth a shot.

avatar image
0

Answer by junglejapes · Dec 12, 2013 at 12:32 AM

Thanks a lot. I hadn't even thought about doing anything other than a straight up c# only super math power solution. The shader solution works. Thanks a lot guys.

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

17 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

Related Questions

How can I implement the ability to 'cut' sprites into arbitrary shapes? 1 Answer

How can I put the single pieces of a sliced Sprite into an array? 0 Answers

Converting 2d sprite to mesh - looking better algorithm 1 Answer

Cutout plane effect on multiple meshes? 1 Answer

multiple textures on one mesh + different Albedos 1 Answer


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