Gamedev:CollisionVolumes: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
x,y,z cylinder
Some refinements
Line 7: Line 7:


==How to see them ingame==
==How to see them ingame==
press ctrl + b and look at the black wireframe shapes around units.
Press ctrl + b and look at the black 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.
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.
Red shapes indicate the unit was hit.


==What else are they used for?==
==What else are they used for?==
Line 31: Line 31:
You have to restart spring.exe for the changes to take effect, there is no way to reload unitdefs.
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.
<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.
(this is relative to what? the unit center set in Upspring?) <span style="color:red">???</span>


<pre>collisionVolumeType = [[box]],</pre>
<pre>collisionVolumeType = [[box]],</pre>
defines the shape. possible are: ''box'', ''sphere'' and cylinders:
defines the shape. possible are: ''box'', ''ellipsoid'' and cylinders:
''CylX'', ''CylY'', ''CylZ''
''CylX'', ''CylY'', ''CylZ''


<pre>collisionVolumeScales = =  [[40 20 55]]</pre>
<pre>collisionVolumeScales = =  [[40 20 55]]</pre>
dimension in X Y Z directions.
dimensions along X Y Z axes.


====boxxy the hitbox editor====
====boxxy the hitbox editor====
Line 52: Line 51:
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 chasis and a cylinder for the turret.


Each piece can have its own collision volume.
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.
 
blabla HOW blablabla


==Can they be changed during gameplay?==
==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.
Yes. One example would be "pop up" turrets that get a smaller hitbox when sunken into the ground etc.
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]]
Line 71: Line 68:


==Which spot on an enemy do units target==
==Which spot on an enemy do units target==
The unit center/height set in Upspring <span style="color:red">???</span>
The model center set in Upspring


==Common problems (and how to solve)==
==Common problems (and how to solve)==
===weapons miss the unit===
===weapons miss the unit===
Weapons like Dgun and torpedos might pass through under the unit if the hitboxes does not extend a bit into the ground/underwater.
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===
===Intersecting hitboxes===
Two near units might refuse to shoot if their turrets intersect each other hitboxes.
Two near units might refuse to shoot if their turrets intersect with each other's hitboxes.


===Fast projectiles passing through collision volumes===
===Fast projectiles passing through collision volumes===
The problem: fast projectiles sometimes fly through small hit volumes without causing damage:
The problem: fast projectiles sometimes fly through small hit volumes without causing damage:
http://h-3.abload.de/img/screenshot_xta_spring_2gmr.jpg
http://h-3.abload.de/img/screenshot_xta_spring_2gmr.jpg
The solution: <code>collisionVolumeTest = true,</code> in the unitDef and hits will register correct.
The solution: <code>collisionVolumeTest = true,</code> in the unitDef and hits will register correctlu.
 
<span style="color:red">Works on what weapon types ???</span>


==Hitbox related weapon tags==
==Hitbox related weapon tags==
<pre>targetBorder = true,</pre>unit targets the border of the hit volume instead of its center.
<pre>targetBorder = 1,</pre> unit targets the border of the hit volume instead of its center.
only works on hitspheres: http://springrts.com/phpbb/viewtopic.php?f=12&t=18824&p=352456&hilit=targetborder#p352456 (???)
only works on hitspheres: http://springrts.com/phpbb/viewtopic.php?f=12&t=18824&p=352456&hilit=targetborder#p352456 (???)


Line 94: Line 89:


==Aircraft==
==Aircraft==
the hitspheres of airplanes seem to be scaled down -50% by the engine.
The hitspheres of airplanes seem to be scaled down -50% by the engine.


==Engine code==
==Engine code==

Revision as of 08:32, 14 May 2011

What is a collision volume?

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

Units_with_hitboxes.jpg

How to see them ingame

Press ctrl + b and look at the black 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?

  • collision between units
  • when selecting units, where you have to click

???

How to edit their shape

What are they measured in?

in elmos.

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.

editing_hitbox_in_upspring.jpg

in the UnitDef

There are numerous 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.

collisionVolumeOffsets = [[0 0 0]],


position of the collision volume, in this example center of the unit. The value is relative to the unit center set in Upspring.

collisionVolumeType = [[box]],

defines the shape. possible are: box, ellipsoid and cylinders: CylX, CylY, CylZ

collisionVolumeScales = =  [[40 20 55]]

dimensions along X Y Z axes.

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

forum thread

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.

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 There seems to be no noticeable cpu usage when dynamically adjusting collision volumes.

CPU Usage of non-sphere volumes

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

When a unit uses a box volume, is the unit radius that was set in Upspring used for anything? Unit-Unit collision? Selecting?

Which spot on an enemy do units target

The model center 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.

Fast projectiles passing through collision volumes

The problem: fast projectiles sometimes fly through small hit volumes without causing damage: screenshot_xta_spring_2gmr.jpg The solution: collisionVolumeTest = true, in the unitDef and hits will register correctlu.

Hitbox related weapon tags

targetBorder = 1,

unit targets the border of the hit volume instead of its center.

only works on hitspheres: http://springrts.com/phpbb/viewtopic.php?f=12&t=18824&p=352456&hilit=targetborder#p352456 (???)

others???

Aircraft

The hitspheres of airplanes seem to be scaled down -50% by the engine.

Engine code

related engine parts are: 1 ... 2 ... ...