Jump to content

Guide to new collision features in 4.x


GeneralCamo

Recommended Posts

Author: Jonwil, Generalcamo

Difficulty: 5

 

 

Every physics object in Renegade has a collision group type that describes which other collision types it can collide with.

Note that this has nothing to do with the W3D collision settings (physical, projectile, vis, camera, vehicle) that you set in gmax/3ds max.

 

 

Collision types

Scripts 4.x adds a number of new collision group types for various features including boats, subs, hover units, amphibious units and underground units.

The full list of collision types (and the in-game numbers that represent them) is:

  • Default = 0
  • Uncollideable = 1
  • Terrain Only = 2
  • Bullet = 3
  • Terrain and Bullet = 4
  • Bullet Only = 5
  • Soldier = 6
  • Soldier Ghost = 7
  • C4 = 8
  • Underground = 9
  • Soldier Only = 10
  • Soldier Bullet = 11
  • Terrain = 15
  • Water Surface = 16
  • Water Edge Block = 17
  • Water Edge Allow = 18
  • Beach Edge = 19
  • Naval Unit = 20
  • Beaching Unit = 21
  • Hover Unit = 22
  • Amphibious Unit = 23
  • Amphibious Unit Floor = 24
This image shows what collision types each collision type can collide with:

Collision_group_reference_dark.png

 

Note that you can put any collision type on any object e.g. you aren't restricted to using C4 on just C4 objects. The names just indicate their intended purpose.

 

 

Default preset collisions

  • Terrain always has a collision type of "Terrain". Tiles by default have a collision type of "Terrain" by default but can be changed using the drop-down list in leveledit
  • Objects (i.e. the stuff under "object" in leveledit) can have the script SH_CustomCollisionGroup added that will let you set the collision group using the numbers in the list above
  • By default beacons will have a collision group type of "Terrain and Bullet"
  • C4 will have a collision group type of "C4"
  • Cinematic objects will have a collision group type of "Terrain"
  • Powerups will have a collision group type of "Terrain" or possibly "Uncollideable" (I cant tell from the code which it is, seems to depend on whether its pre-placed in LE or spawned by a script/spawner)
  • Special Effects objects will have a collision group type of "Uncollideable"
  • Soldiers can have various collision groups at runtime depending on their state so using SH_CustomCollisionGroup on a soldier object will not work
  • All objects not otherwise mentioned get collision type "default"
For programmers

 

 

You can look at the source code of SH_CustomCollisionGroup and the enum in physdefclass.h to see how to set collision group programmatically.

 

The Disable_All_Collisions script command sets the objects group type to "Uncollideable". The Disable_Physical_Collisions script command sets the objects group type to "Bullet Only" and the Enable_All_Collisions script command sets soldier objects to "Soldier" and all other objects to "Default"

 

 

 

 

Example from TS: Reborn

This next part will describe how things are set up for amphibious and hover units in Tiberian Sun Reborn.

 

Firstly, you need to create the vehicles.

 

GDI Amphibious APC

The only special thing you need for the amphibious unit (which is designed to be unit that drives along the ground but appears to be "floating" when in the water) is a copy of SH_CustomCollisionGroup on the vehicle with the value set to 23 (aka "Amphibious Unit")

 

GDI Hover MLRS

For hover units (which is for anything designed to travel on top of water and "hover"), you need a copy of SH_CustomCollisionGroup on the vehicle with the value set to 22 (aka "hover unit"). You will probably also want to make the wheel bones and such of your vehicle invisible so it appears to be hovering (The Hover MRLS in Reborn is set up as a tracked vehicle which seems to work best for hover vehicles rather than a wheeled vehicle)

 

Hidden mesh for hovering

-Next up you need special geometry on the map to make things work correctly. Firstly create a mesh (in a separate w3d file from the main terrain) for the "water surface" (this is what hover units will drive on top of). This shouldn't be the actual water surface with the texturing on it. It should have flags set to "hidden" and "physical collision" and nothing else.

-Export this as "terrain" in gmax/max. Create a tile in leveledit and assign this mesh. It needs to be StaticPhys and needs to have IsNonOccluder ticked, Collision Group set to "water surface" and "visibility mode" left at "default"

-Then place your tile on the map like you would with any other tile.

 

Hidden mesh for the Amphibious APC

Next up you need to create another similar mesh for the "Amphibious Unit Floor". This is what the amphibious unit will drive on when in the water (so it should be placed such that the vehicle appears to be floating on the water surface when its driving on it, below the water surface) It should be created just like the "Water Surface" mesh above with the same flags and settings except that it should have Collision Group set to "amphibious unit floor".

 

 

 

Note that it is the size/position of the vehicle's Worldbox (which for vehicles has Physical collision ticked), not the geometry itself (which doesn't have Physical collision ticked) that determines how low or high the vehicle rides.

 

For example, the Reborn Amphibious APC has a larger worldbox with more worldbox underneath the vehicle than usual so that when it drives on the "amphibious unit floor" it will achieve the desired height so it appears to be floating on the top of the water.

 

The boats in APB (including the naval transport) have part of their structure (the nit that is underwater) sticking out from below their worldboxes so that when they ride on the "water surface" mesh, part of the geometry sits underneath the water.

 

The submarines in APB have any part that is visible above the water when its surfaced to be protruding above the worldbox (as the water surface will act as a "lid" and keep the worldbox from moving past it)

 

 

 

Generic naval unit setup

The vehicles

Ok, now for the tutorial on naval units. Other than the aforementioned worldbox changes, they are just like any other vehicle. The boats (including naval transports) are set up as tracked vehicles (with invisible wheels). The submarines need to be set up as VTOL vehicles so the can move up and down in the water. The only other setting required is to set the "type" as appropriate (either Boat or Sub depending on what you are making). Everything else is as normal for vehicles.

 

As for scripts, both boats and subs require SH_CustomCollisionGroup with a setting of 20 aka "naval unit".

Units that can come onto the beach but not onto land more generally (i.e. naval transports) need a setting of 21 aka "beaching unit".

 

The naval-colliding meshes

For the water surface in the naval logic, you need to make the actual visible water surface a separate mesh.

You need 2 meshes:

  • One facing up for the top surface (which will dictate how low into the water boats will go)
  • One facing down for the bottom surface (which will dictate how high up subs will go) and is what people in submarines see when they are underwater.
They need "physical" collision ticked and nothing else (technically they dont NEED to be 2 separate meshes but it should be totally fine to have them separate). Export them as terrain.

 

In LevelEdit, you need to make this as a tile with StaticPhys, "IsNonOccluder" ticked, "water surface" collision and "default" visibility mode and place it in your level.

 

Blockers

Next up, you need a blocker around the edge of the water (this will limit where naval vehicles can go, so they won't leave the water and roll around on the normal ground). This should also be "physical" collision only and should be hidden so it cant be seen. In-game, it's the same as the water surface (StaticPhys etc) except that it needs either collision group:

  • "water edge (allow)" (if you want to allow soldiers and normal vehicles into the water) or
  • "water edge (block)" (if you want to block soldiers and normal vehicles from entering the water)
Finally, if you have any vehicles with "beaching unit" set on them, you need another blocker further in (just like the water edge) with "beach edge" collision group.

 

This concludes the tutorial on collision detection and how to use it to build boats, submarines, naval transports, amphibious units and hover units.

 

Anyone with questions on all this stuff (or if you are having problems getting it working), feel free to post here or hit me up on IRC/IM.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...