Gamedev:CollisionVolumes: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
m Changed link to active repositories
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
==What is a collision volume?==
= Collision Volumes =
The collision volume is a geometric shape around (almost) all Spring units.
== What is a collision volume? ==
If a projectile collides with this shape, the engine registers it as a hit.
The collision volume is a geometric shape around Spring units and features. If a projectile collides with this shape, the engine registers it as a hit. Other names are hitbox, hitsphere etc.
Other names are hitbox, hitsphere etc.


http://springrts.com/mediawiki/images/0/06/Units_with_hitboxes.jpg
[[File:Units_with_hitboxes.jpg|256px|right]]


==How to see them ingame==
== How to see them ingame ==
Press alt + v or type '''/debugcolvol''' into chat.
Press alt + v or type '''/debugcolvol''' into chat.
Look at the purple wireframe shapes around units.
Look at the purple wireframe shapes around units.
Line 12: Line 11:
Red shapes indicate the unit was hit.
Red shapes indicate the unit was hit.


==What else are they used for?==
== What else are they used for? ==
*line-of-fire calculations
* line-of-fire calculations
*mouse-click detection when selecting a single unit
* mouse-click detection when selecting a single unit


==How to edit their shape==
==How to edit their shape==
===What are they measured in?===
[http://answers.springlobby.info/questions/339/dimension-of-spring in elmos.]
===In Upspring===
===In Upspring===
in the 3D view, click on the blue "3D" text and a menu opens.<br>
In the 3D view, click on the blue "3D" text and a menu opens.<br>
Click "draw model radius + height"<br>
Click "draw model radius + height"<br>
At the right side, go to the "Model" tab and edit the values.<br>
At the right side, go to the "Model" tab and edit the values.<br>
With Upspring, you can only define sphere shaped collision volumes.<br>
With Upspring, you can only define sphere shaped collision volumes.<br>


editing_hitbox_in_upspring.jpg
===In the Def===
There are numerous [[Gamedev:UnitDefs#Collision_Volumes|tags]] that control shape, size and position of the collision volume. You have to restart Springfor the changes to take effect, there is no way to reload unit and feature defs.


===in the UnitDef===
===boxxy the hitbox editor===
There are numerous [http://springrts.com/wiki/Units:FBI tags] that controll shape, size, position of the collision volume.
You have to restart spring.exe for the changes to take effect, there is no way to reload unitdefs.
 
<pre>collisionVolumeOffsets = [[0 0 0]],</pre><br>position of the collision volume, in this example center of the unit. The value is relative to the unit center set in Upspring.
 
<pre>collisionVolumeType = [[box]],</pre>
defines the shape. possible are: ''box'', ''ellipsoid'' and cylinders:
''CylX'', ''CylY'', ''CylZ''
 
<pre>collisionVolumeScales = =  [[40 20 55]]</pre>
dimensions along X Y Z axes.
 
====boxxy the hitbox editor====
This creation allows you move hitboxes by pressing buttons.
This creation allows you move hitboxes by pressing buttons.
This way you can get the needed numbers and copy them to the unitdef file.
This way you can get the needed numbers and copy them to the unitdef file.
Line 46: Line 31:
http://h-4.abload.de/img/loveandtrolls25t5u.gif
http://h-4.abload.de/img/loveandtrolls25t5u.gif


[http://springrts.com/phpbb/viewtopic.php?f=14&t=24882 forum thread]
{{forumlink|topic=24882|title=Its Boxxy!}} (forum)


===Multiple collision volumes===
===Multiple collision volumes===
A unit can have multiple collision volumes. For example a tank could use a box for the chasis and a cylinder for the turret.
A unit can have multiple collision volumes. For example a tank could use a box for the chassis and a cylinder for the turret.


Each piece can have its own collision volume. <pre>usePieceCollisionVolumes = true,</pre> will cause each piece on the model to have an autogenerated hitvolume; unwanted hitvolumes can then be removed with Lua.
Each piece can have its own collision volume. {{xtaglink|Gamedev:UnitDefs|usePieceCollisionVolumes|true}}, will cause each piece on the model to have an autogenerated hitvolume; unwanted hitvolumes can then be removed with Lua.


==Can they be changed during gameplay?==
==Can they be changed during gameplay?==
Line 57: Line 42:
See <code>Spring.SetUnitCollisionVolumeData()</code> and <code>Spring.SetUnitPieceCollisionVolumeData()</code>
See <code>Spring.SetUnitCollisionVolumeData()</code> and <code>Spring.SetUnitPieceCollisionVolumeData()</code>
at [[Lua_SyncedCtrl]].
at [[Lua_SyncedCtrl]].
There seems to be no noticeable cpu usage when dynamically adjusting collision volumes.
Example: [http://code.google.com/p/xta-springrts/source/browse/trunk/LuaRules/Gadgets/unit_dynamic_collision_volume.lua Dynamic Collision Volume gadget] and it's [http://code.google.com/p/xta-springrts/source/browse/trunk/LuaRules/Configs/CollisionVolumes.lua configuration file].


==CPU Usage of non-sphere volumes==
Example: [https://github.com/Balanced-Annihilation-Reloaded/BAR.sdd/blob/master/luarules/gadgets/unit_dynamic_collision_volume.lua Dynamic Collision Volume gadget] and it's [https://github.com/Balanced-Annihilation-Reloaded/BAR.sdd/blob/master/luarules/configs/collisionvolumes.lua configuration file].
For the engine, collision with a sphere are fastest to calculate. Cylinders and boxes require more math and so are slower.
How much does it really matter? No idea.


==Unit radius & height VS collision volume==
==Unit radius & height VS collision volume==
Even when a unit defines a collision volume that is not a sphere, the ''radius'' and ''height'' values set in Upspring still have a number of purposes. To name a few examples: ''height'' is used to decide whether a ship can move over an underwater structure, ''radius'' is used in collision handling for aircraft.
Even when a unit defines a collision volume that is not a sphere, the ''radius'' and ''height'' values set in Upspring still have a number of purposes. To name a few examples: ''height'' is used to decide whether a ship can move over an underwater structure, ''radius'' is used in collision handling for aircraft. Most importantly, all collision checks first do a pre-check with the unit ''radius'' before doing the colvol checks. Ergo the unit ''radius'' must be larger or equal to the colvol!


==Which spot on an enemy do units target==
==Which spot on an enemy do units target==
The model center set in Upspring
The model centre set in Upspring


==Common problems (and how to solve)==
==Common problems (and how to solve)==
Line 77: Line 58:
Two near units might refuse to shoot if their turrets intersect with each other's hitboxes.
Two near units might refuse to shoot if their turrets intersect with each other's hitboxes.


===Fast projectiles passing through collision volumes===
[[Category:Game Dev]]
The problem: fast projectiles sometimes fly through small hit volumes without causing damage:
http://h-3.abload.de/img/screenshot_xta_spring_2gmr.jpg
The solution: <code>collisionVolumeTest = 1,</code> in the unitDef, switches to continuous rather than discrete collision tests and hits will then register correctly.
 
==related weapon tags==
<pre>targetBorder</pre>
 
Units will target the nearest / farthest edge (''targetBorder=1'' / ''targetBorder=-1'') of a hit volume instead of its center (''targetBorder=0'') along their line of fire. Works on all volume types.
 
==Aircraft==
The hitspheres of airplanes seem to be scaled down -50% by the engine.
 
This is removed in 0.83, [https://github.com/spring/spring/commit/dca8d0a5ed2ed5b77f837b6427498061959e7f0d| see here]
 
==Engine code==
related engine parts are:
1 ...
2 ...
...
 
[[Category:Unit development]]

Latest revision as of 12:27, 9 January 2020

Collision Volumes

What is a collision volume?

The collision volume is a geometric shape around Spring units and features. If a projectile collides with this shape, the engine registers it as a hit. Other names are hitbox, hitsphere etc.

How to see them ingame

Press alt + v or type /debugcolvol into chat. Look at the purple wireframe shapes around units. If you can not see them, the collision volume might be blocked from view by the 3D model or be very offset like underground or in the sky. Red shapes indicate the unit was hit.

What else are they used for?

  • line-of-fire calculations
  • mouse-click detection when selecting a single unit

How to edit their shape

In Upspring

In the 3D view, click on the blue "3D" text and a menu opens.
Click "draw model radius + height"
At the right side, go to the "Model" tab and edit the values.
With Upspring, you can only define sphere shaped collision volumes.

In the Def

There are numerous tags that control shape, size and position of the collision volume. You have to restart Springfor the changes to take effect, there is no way to reload unit and feature defs.

boxxy the hitbox editor

This creation allows you move hitboxes by pressing buttons. This way you can get the needed numbers and copy them to the unitdef file.

loveandtrolls25t5u.gif

Its Boxxy! (forum)

Multiple collision volumes

A unit can have multiple collision volumes. For example a tank could use a box for the chassis and a cylinder for the turret.

Each piece can have its own collision volume. usePieceCollisionVolumes = true, will cause each piece on the model to have an autogenerated hitvolume; unwanted hitvolumes can then be removed with Lua.

Can they be changed during gameplay?

Yes. One example would be "pop up" turrets that get a smaller hitbox when sunken into the ground etc. See Spring.SetUnitCollisionVolumeData() and Spring.SetUnitPieceCollisionVolumeData() at Lua_SyncedCtrl.

Example: Dynamic Collision Volume gadget and it's configuration file.

Unit radius & height VS collision volume

Even when a unit defines a collision volume that is not a sphere, the radius and height values set in Upspring still have a number of purposes. To name a few examples: height is used to decide whether a ship can move over an underwater structure, radius is used in collision handling for aircraft. Most importantly, all collision checks first do a pre-check with the unit radius before doing the colvol checks. Ergo the unit radius must be larger or equal to the colvol!

Which spot on an enemy do units target

The model centre set in Upspring

Common problems (and how to solve)

weapons miss the unit

Weapons like Dgun and torpedos might pass through under the unit if the hitvolume does not extend a bit into the ground/underwater.

Intersecting hitboxes

Two near units might refuse to shoot if their turrets intersect with each other's hitboxes.