Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Maximum number of rays?

Discussion in 'Physics' started by SVKsuli, Oct 20, 2018.

  1. SVKsuli

    SVKsuli

    Joined:
    Mar 23, 2014
    Posts:
    63
    Hello, what you people think is maximum number of rays that i could use in 2D game to keep it still playable.

    I curently using around 400 rays in update (yes a lot), and with my cpu intel core i5 3.2Ghz skylake (quite old) i hold it easily around 150fps.
    Is it mean that i can use them when it is stable? or is it bad idea?
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Definitely one of those piece of string.Length() questions.

    • find your minimum CPU requirement for your game
    • if it runs at your minimum required framerate you win
    • else use less rays or optimise
    This is the sort of useless (I mean that factually, not intending to offend) question I see a lot of. It's so vague, so pointless because everything you are doing consumes CPU, from drawing to input, to AI and so on. Raycasts also use CPU. Do you see where I am going? It is utterly impossible for us to answer your question, especially since how much raycast costs you in millisecs depends on how it is used, why it will be used, if it is sliced, uses threaded API and so on... it could be that the game is better having a lot more CPU spent on raycasts so you optimise other things. And so on.

    So in future you have to make these judgement calls, it's actually one of your jobs - and to help you, once you know your targets, get used to the profiler. If it becomes a problem then it's time to optimise :)
     
  3. SVKsuli

    SVKsuli

    Joined:
    Mar 23, 2014
    Posts:
    63
    Yea you have aboslutly true, but my question is it ok to thinking about it like, i looking on profiler, its stable over 100fps then even though its 2D game its ok? Or how can i know what is ok and what not, what if i have the fastest cpu that i can buy then how i can optipalize this game when i can easily calculate a lot of things at once?
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How would I know if it's OK?
     
  5. SVKsuli

    SVKsuli

    Joined:
    Mar 23, 2014
    Posts:
    63
    yea thats my qeustion too :) ,like if its stable on my pc then i can say its optimalized or i need to take this game and trying it on many different PCs? I dont have much experiences with how to correctly optimalized game.