Bounding box: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (bounding box isn't related to hitboxes! (verified in l4d with the tank and survivors))
Line 1: Line 1:
[[File:Metrocop_bbox_engine.jpg|200px|right|The bounding box of [[npc_metropolice]].]]
[[File:Metrocop_bbox_engine.jpg|200px|right|The bounding box of [[npc_metropolice]].]]


A '''Bounding Box'''  is an invisible box that defines the rough size of an entity. It's chiefly used to determine when the entity is visible and to perform  [[cheap]] [[QPhysics]] collision tests (often before moving on to more expensive ones: for example, bullets are only tested against [[hitbox]]es if they are first found to intersect with the given entity's bounding box).
A '''Bounding Box'''  is an invisible box that defines the rough size of an entity. It's chiefly used to determine when the entity is visible and to perform  [[cheap]] [[QPhysics]] collision tests. (often before moving on to more expensive ones)
 
<!-- This is for the boxes from ent_absbox only
(often before moving on to more expensive ones: for example, bullets are only tested against [[hitbox]]es if they are first found to intersect with the given entity's bounding box).
-->


{{note|Parts of an entity that protrude from its bounding box will not pass QPhysics collision tests. This includes hitboxes.}}
{{note|Parts of an entity that protrude from its bounding box will not pass QPhysics collision tests. This includes hitboxes.}}
Line 7: Line 11:
== Rotation ==
== Rotation ==


Bounding boxes are always aligned to the world's axes. They never rotate. This is presumably because of their use for collision detection of players: it would be impossible to turn around in a tight corridor if the four corners of your bounding box rotated with you. Axis-aligned boxes are also far cheaper to compute.
Bounding boxes are always aligned to the world's axes; they never rotate. This is presumably because of their use for collision detection of players: it would be impossible to turn around in a tight corridor if the four corners of your bounding box rotated with you. Axis-aligned boxes are also far cheaper to compute.


While this isn't a huge issue for objects that are roughly square from above, it makes oblong dimensions difficult to manage without switching to [[VPhysics]]. When VPhysics isn't an option there isn't much that can be done: a [[Day of Defeat: Source]] player who has gone prone has an oblong shape that can rotate through a full 360&deg;, which Valve could only accommodate for by creating a 'squished' bounding box that leaves the head and feet sticking out at all times (an image of this would be nice).
While this isn't a huge issue for objects that are roughly square from above, it makes oblong dimensions difficult to manage without switching to [[VPhysics]]. When VPhysics isn't an option there isn't much that can be done: a [[Day of Defeat: Source]] player who has gone prone has an oblong shape that can rotate through a full 360&deg;, which Valve could only accommodate for by creating a 'squished' bounding box that leaves the head and feet sticking out at all times (an image of this would be nice).

Revision as of 06:39, 21 August 2021

The bounding box of npc_metropolice.

A Bounding Box is an invisible box that defines the rough size of an entity. It's chiefly used to determine when the entity is visible and to perform cheap QPhysics collision tests. (often before moving on to more expensive ones)


Note.pngNote:Parts of an entity that protrude from its bounding box will not pass QPhysics collision tests. This includes hitboxes.

Rotation

Bounding boxes are always aligned to the world's axes; they never rotate. This is presumably because of their use for collision detection of players: it would be impossible to turn around in a tight corridor if the four corners of your bounding box rotated with you. Axis-aligned boxes are also far cheaper to compute.

While this isn't a huge issue for objects that are roughly square from above, it makes oblong dimensions difficult to manage without switching to VPhysics. When VPhysics isn't an option there isn't much that can be done: a Day of Defeat: Source player who has gone prone has an oblong shape that can rotate through a full 360°, which Valve could only accommodate for by creating a 'squished' bounding box that leaves the head and feet sticking out at all times (an image of this would be nice).

Object-aligned

Object-aligned bounding boxes rotate with their entity. They appear to be linked to VPhysics to some extent.

Todo: How well do they work?

Defining

Source will automatically create bounding boxes. But if you need to tweak the results:

  • Modellers use the $bbox QC command
  • Programmers call UTIL_SetSize() or CBaseEntity::SetSize()

Uses

  • QPhysics collision detection (mainly NPCs and players)
  • Prerequisite for hitbox collision detection
  • Line of sight tests
  • Visleaves occupied by an entity

See Also