MontyTRC89/TombEngine

Collision script interface prototyping

Opened this issue · 2 comments

I suggest to plan forthcoming Lua collision interface here, and to collect all features that it must implement.

First off, we must decide how to implement collision polling in a Lua:

  1. Should it be a collection of methods, every one of which will provide a specific result?
  2. Should it be a new Lua class / structure, which will be filled with a single call (like GetCollisionInfo in C++ code)?

And which features it must implement:

  • Is there a solid room geometry in a given point?
  • What is the vertical distance to the floor in a given point?
  • What is the vertical distance to the ceiling in a given point?
  • What is horizontal distance to the solid room geometry in a given point and direction?
  • What is the material of the nearest floor below a given point?
  • Which room is above/below/within a given point?
  • Is there a static mesh contained within a given point?
  • Get nearest free space point in relation to a given point enclosed in a room geometry, and a penetration vector to it (so called "shifts")
  • Get slope direction and angle below a given point

Imo a class will be most convenient and easy to use. Essentially this, but a Lua version:
https://github.com/MontyTRC89/TombEngine/blob/sezz_point_collision_class/TombEngine/Game/collision/PointCollision.h

An attempt at collecting related TRNG checks - may not be fully exhaustive, but should provide an overview of what's available there as a base. Not all are strictly collision-related, as it is a big mixed bag in there.

TRNG via Editor:

1. Condition triggers - collision

  • movable is touching Lara with its (given) mesh (dropdown list available to select mesh number)
  • Lara is touching (selected) moveable
  • Lara is touching (selected) moveable with her (selected) mesh
  • Lara is touching (selected) creature type
  • Lara is touching moveable of (selected) slot type
  • Lara is touching some static of (selected) slot static type
  • Lara is touching the (selected) static item

2. Condition triggers - fragmented triggers

  • check if Lara is in custom defined circle
  • check if Lara is in (given) fragment of 2x2 / 3x3 / 4x4 sector grid (Lara is over fragment, over any fragment except, Lara is touching fragment [PAD trigger], PAD + inverse [Lara touching any fragment except specified] - similar additional checks can be applied to other conditions on this list)
  • checks if Lara is in (direction - East/West/North/South) side triangle of a given size
  • checks if Lara is in (direction e.g. North-West) corner triangle of given size
  • checks if Lara is in quadrilateral
  • checks if Lara is in rhombus (pretty sure no one uses some of these...)
  • checks if Lara is in the sector with the center in (direction e.g. south-west)
  • checks if Lara is in the sector with the center in the middle (direction e.g. west) side

3. Condition triggers - Lara + extra

  • Lara's distance from movable is less or equals xyz clicks or units
  • random - condition is true with (x) chances on 64 computed in (y) way (select chances in dropdown, and choose if tested continuously while Lara is over sector, or only when she enters the sector)

TRNG via script:

1. Environmental conditions (condition + distance + optional flags)

A mixture of distance checks, item checks, animation and state checks. Examples:

  • Distance from ceiling, distance from East/North/South/West wall, distance from floor
  • Lara is in left or right "side sector" - checks Lara's position within the given sector, if she's near the left or right border of a sector
  • Lara is in "micro strip" - sector divided by 32 strips, condition is to determine where exactly Lara is within this (Lara has to be in a precise spot for the condition to become true)
  • Position checks - central, hortogonal (non-diagonal, for Lara to have to face a wall straight to climb, etc.), middle (almost exactly at centre of sector), left corner, right corner (of a sector)
  • Vertical orientation of Lara
  • Distance to item checks (+ position - left/right/in front/above/under)
  • Orientation checks vs specific item (e.g. Lara is face to face with skeleton)
  • Geometry checks
    --> climbable wall in front/back/left/right
    --> internal corner at left/right while climbing or hanging + outside corner left/right
    --> left/right space when climbing or hanging (identify if there's space on Lara's left/right in diff. states)
    --> monkey to climbable wall, checks if there's a hole in the floor Lara can go down or fall into in front/back/left/right
    --> no block (=no wall) left/right/back/in front, support - checks for "support" (=wall with correct height) where Lara could hang in wall in front with min. max. height acceptable + clicks of space over the "support"
    --> wall hole in front = similar to "support", checks for support in front wall by checking also the height of the hole in the wall (min+max height, min+max space)
  • State checks
    --> animation complete (last frame of animation)
    --> frame number (of animation) or frame range
    --> free hands (nothing in Lara's hands) or item in hands
    --> Lara is still, on vehicle, on monkey ceiling, on land, underwater, enemy sees Lara, floating (on water surface), flying down/up (Lara jumping upward/downward state), player woke up (after Lara being idle for some time)
    --> Lara is in X room (room number)

2. Global Triggers - Checks for items, creatures, slots, etc.

  • Distance from item
  • Lara collides with creature
  • Lara collides with slot
  • Lara collides with static slot
  • Lara collides with item
  • For slot and item, extra flag can detect 3 different types of collision:
    --> bounding box collision (checks 2 collision boxes of current frame for both movables overlap in 3D space, this is the default check)
    --> pushing item collision (similar to bound box, but also needs one object to push the other)
    --> mesh on mesh collision (each mesh of first movable using sphere meshes is compared with each mesh of second movable to detect collision, used rarely to check collision of Lara with some traps)

3. TestPosition

Special command to determine Lara's position and orientation vs an item of a certain slot type, with ranges (min. max. horizontal orientation difference, min distance, max distance etc. If Lara is within these ranges and additional conditions are true (e.g. item present in inventory, action button is pressed) she will be aligned to a given position relative to that item/slot (like when she is near a switch, you press action and she steps to the switch to position herself to pull it). Can be quite useful for special setups (NPC interaction, underwater puzzle, underwater wall kick like in AOD).

Syntax: TestPosition= IdTestPosition, Flags (TPOS_...), Slot Moveable, XDistanceMin, XDistanceMax, YDistanceMin, YDistanceMax, ZDistanceMin, ZDistanceMax, HOrientDiffMin, HOrientDiffMax, VOrientDiffMin, VOrientDiffMax, ROrientDiffMin, ROrientDiffMax