0
\$\begingroup\$

Im currently using the Unity Engine and the Box2D Physics Engine.

I have this line of code:

    "RaycastHit2D ray = Physics2D.Raycast(origin, direction, distance);"

Im planning to use this line of code ... like "a lot" times (maybe like 100.000 times per frame)

And I have 3 simple Questions about Raycasting and Performance:

  1. How much does 1 Raycast cost (approximately).
  2. Is the Raycast processed by the CPU now or by the GPU?
  3. Does the number of the BoxColliders affect the cost of the Raycast? (for example: If I have 1000.000 Tiles on the map which have box Colliders, does one ray has the same performance cost as if i would have 1 single Tile? And if I have 1000.000 tiles - is the cost millionfold then?
\$\endgroup\$
4
  • \$\begingroup\$ for your 3rd question, the cost is per raycast call. So it doesn't really matter how many objects you have on screen (other than the impact that those objects make regardsless of raycasts). You'll probably have huge issues with that many raycast calls though (Try to reduce the number or don't update per frame maybe?). \$\endgroup\$ Commented Jan 16, 2017 at 7:17
  • 1
    \$\begingroup\$ Question 1 does not really have an answer as it highly depends on various factors. Unless you wanted an answer in big O notation? (which, according to this question is O(log n)) And why is question 2 relevant? You don't really have influence on it anyway as that is handled by the engine. (And AFAIK it's all performed on the CPU) \$\endgroup\$ Commented Jan 16, 2017 at 7:31
  • \$\begingroup\$ Why do you think you need to raycast 100 times per frame? \$\endgroup\$ Commented Jan 17, 2017 at 17:39
  • \$\begingroup\$ I'm not sure about this but I think what you're trying to do is this: redblobgames.com/articles/visibility and casting 100,000 rays per frame is not the way to go about this. \$\endgroup\$ Commented Jan 18, 2017 at 8:15

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.