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
1
Question by stevenp · Feb 16, 2012 at 07:51 AM · animationinstantiateiphone

Fruit Ninja - Cut fruit effect

Hi fellas!

I want to make a game similar to Fruit Ninja and I don't really have an idea on how to create the effect of the fruit cut in half. I thought about removing the fruit object and instantiate 2 separate objects with texture of fruit cut in half on them but I'm not sure if it's a good way because I'm creating for iPhone. I'm afraid in the end, there will be too much objects on the screen (let's say if the player cut 5 fruits, there will be 10 objects on the screen) and it will cause the game to lag. I appreciate any tips and advice about this. Thank you in advance =)

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
3
Best Answer

Answer by mpavlinsky · Feb 16, 2012 at 02:55 PM

Well anyway you cut it (no pun intended) you're going to have to be able to display MaximumFruits*2 objects on your screen minimum. You can curb the load a little bit by making the halves static geometry and batching them since at least 2 will be the same (if the fruit is perfectly bisected) and they aren't animating. I honestly don't think the rendering is that big of an issue performance wise, I wouldn't instantiate them on the go as you suggest though. A better strategy would probably just be to define the maximum number of any given fruit that can be on the screen at once and then instantiate all the fruit halves for them when you load your scene and just don't render or use them until a player cuts a fruit.

Comment
Add comment · Show 7 · 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 stevenp · Feb 16, 2012 at 04:00 PM 0
Share

I've actually tried instantiating multiple objects at once on the screen. I tried 15 objects (I pick 15 because it is so far the most amount of objects to appear on the screen) at once and no problem for iPad 2 and iPhone 4S. However, when tested on iPhone 3GS the game became lag.

I've tried combining 2 objects and position them to make them appear as a single object but it cannot be done because no matter how there will be a single line at the middle of the two objects when I applied the texture.

avatar image mpavlinsky · Feb 16, 2012 at 04:54 PM 0
Share

Having 15 objects is not hard on the 3GS or any other platform in general, you may want to profile your code and see what the root issue is. I'm sure you could improve your performance by optimizing scripts, reducing the quality of your models, and using more efficient rendering techniques depending on what the bottle neck is.

As far as combining the two objects I would ins$$anonymous$$d just have a model that is the whole fruit and instantiate as many of those as you need in using the same method I described above. Then just deactivate the whole fruit and move the two halves of fruit into place (rotate them correctly, set physics velocities, play a particle effect and do whatever else Fruit Ninja does) when the player swipes the fruit.

avatar image stevenp · Feb 16, 2012 at 05:59 PM 0
Share

Yeah, my code is still messy because I need to finish the other core features in the prototype so I hope the optimization will pay off in the end.

I will try to use the method you suggest and I will give the update as soon as I can. Thanks for the tips =)

avatar image stevenp · Feb 17, 2012 at 04:29 AM 0
Share

I've tried instantiating 2 objects and remove the slashed object and I think it is fine. Not really much performance issue even with crappy code. The hard part is only positioning the slashed parts properly and applying realistic movement.

avatar image Ashkan_gc · Feb 17, 2012 at 04:39 AM 1
Share

Don't position them manually. make two empty objects as children of the main fruite and position them in a good way and then just instantiate new objects in their position. you can get their transform either by setting them in 2 variables in inspector or using a foreach on the transform component. the first way is the recommended one.

Show more comments
avatar image
3

Answer by Ashkan_gc · Feb 16, 2012 at 05:42 PM

There is only one optimization in my mind at the moment. instantiate other objects with the main one and just set their gameObject.active property to false or just disable their rendering by setting renderer.enabled to false. You can even do this for the main fruites themselves. let's say this:

  1. Instantiate 5 Orange objects and 10 Orange parts if you at most show 10 of them at the same time.
  2. Then make all of them inactive by setting their active to false.
  3. when you want to instantiate a new orange just set active to true
  4. and when you want to destroy, just set it to false.

the technique is called polling and is very useful because you'll remove much of the overhead of instantiation. Also you can use Graphics.Drawmesh to draw meshes without having gameObjects but then you should calculate movements yourself and without using rigidbodies.

About alverndbl's answer i should say that it seems that he is talking about a solution that could cut meshes at runtime. it's really great for it's usage but doing it on the phone would kill your performance.

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 stevenp · Feb 16, 2012 at 05:54 PM 0
Share

I remove the game objects when they got slashed, so how does setting the gameObject.active state to false differs from my current method?

I don't think I can use Graphics.Drawmesh because it is only for UnityPro according to the documentation =(

avatar image Ashkan_gc · Feb 16, 2012 at 05:59 PM 0
Share

You should first position those inactive gameObjects acording to your main fruite and set their active to true. you should yourself maintain a list of those inactive gameObjects in a List and add and remove them in it. this way you'll not have the overhead of destroying. also ins$$anonymous$$d of destruction you can set active of the current main fruite to false and add it to the inactive list of the main fruite.

avatar image
1

Answer by Alverndbl · Feb 16, 2012 at 12:33 PM

I think I saw something like this in the asset store. Had a webplayer demo too, can't remember the name sorry.

Comment
Add comment · Show 1 · 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 swisscoder · Feb 16, 2012 at 06:30 PM 0
Share

Actually it's Piece$$anonymous$$aker. There is one called Object Cutter as well, but as the single review there hypothesises it's probably of lesser quality.

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

10 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

Related Questions

How to have raindrops randomly instantiate from the sky 2D 1 Answer

Instantiate objects on iPhone affecting performance, strategy. 1 Answer

Attaching Object as child at certain point in animation 2 Answers

Is it possible to adjust an Objects pivot without affecting any of the child objects? 1 Answer

Can you animate instantiated prefabs? 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