• 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
Question by Doneyes · Mar 29, 2013 at 01:53 PM · raycastlagexplosiongrenade

Raycast collider detector lags horribly?

This script makes the game drop down from 30 fps to 3 fps. Here they seem to do it no problem(start at 1:00): http://www.youtube.com/watch?v=Y2C2Y3PiCM8

What is making the lag?

 #pragma strict
 
 var wake : boolean;
 
 var power : float = 1000;
 var damage : int = 1;
 var radius : float = 3;
 
 function Start () {
 
 }
 
 function Update () {
     if(wake == true) {
         Explode();
     }
 }
 
 function Explode() {
  
     var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
     Debug.Log("Count of colliders = "+colliders.Length);
         for (var collider : Collider in colliders) {
             //if (collider.tag == "brick" || collider.tag == "player") {
                 Debug.Log("Found brick or a player");
                 var hit : RaycastHit;
                 if (Physics.Linecast(transform.position, collider.transform.position, hit)) {
                     if (hit.collider == collider) {
                     Debug.Log("No obstructions");
                         if (hit.rigidbody)
                             hit.rigidbody.AddExplosionForce(power, transform.position, radius, 3.0);
                 }
             }
         }
     //}
 }
Comment

People who like this

0 Show 4
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 almostsync · Mar 29, 2013 at 02:00 PM 1
Share

When do you turn "wake" true and false? My guess is, as you call it from your Update-loop, you should set wake = false after you call explode()...

avatar image Doneyes · Mar 29, 2013 at 02:31 PM 0
Share

This helps a lot, but in the game I could expect several of these going off at the same time. What could I add to the colliders(not tags or layers) that would single them out so only a few rays are drawn to the colliders?

avatar image almostsync · Mar 29, 2013 at 02:43 PM 1
Share

you probably could add the forces of multiple exlposions for each collider before applying them, but I'm not sure if this is needed. remember you only need to add an explsion force once per collider and explosion, it's not a continuous force, more an impulse. unless you target the really old android or ios devices, you should be able to make quite a few explosions. But it's true, I'd remove the Log calls from the update for testing, rather set a boolean that you could display in a GUI or such.

avatar image whydoidoit · Mar 29, 2013 at 02:45 PM 0
Share

Converted to an answer for future seekers :)

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by whydoidoit · Mar 29, 2013 at 02:34 PM

Debug.Log every frame will kill your framerate... That's damn expensive as it walks the stack

Comment
Doneyes

People who like this

1 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 whydoidoit · Mar 29, 2013 at 02:40 PM 0
Share

I'd suggest Debug.DrawRay with a specific colour and a time to indicate what happened.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Collider OnMouseDown movement lag 0 Answers

multiple raycasts in sphere shape (grenade explosion) 1 Answer

'SendMessage' is not a member of 'UnityEngine.RaycastHit'. 1 Answer

Raycast Lag - DebugDrawRay always one frame behind 0 Answers

Make grenade roll out when it leaves hand 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