Turning on Soft Collision for static objects and vice versa

(Based on l.m.’s tutorial from trlevel.de https://www.trlevel.de/lexicon/index…tatics-setzen/ code credit goes to him)

Tomb Engine has a default hard collision on for all statics. However, there may be cases where you just want to have some statics have soft collision. Well there are 2 ways to achieve this:

– Setting soft collision using static slots
– Setting soft collision using static’s lua name set in Tomb Editor

I shall go through the 2 methods.

you will need:
– basic understanding of array (in Lua they are called tables)
– basic understanding of loops (especially nested loop, more on that later)
– basic understanding of pairs() function.
– Static:SetSolid() command (https://lwmte.github.io/2%20classes/…tatic:SetSolid)

again if you don’t know anything about the arrays, loops etc then I recommend you to read the tutorial: https://github.com/Stranger1992/Tomb…a-Basics-Guide

Setting soft collision using static slots

the whole code is as follows:

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

function SetStaticsSoftCollision()
    local staticSlots = {
        0,2,4,5,6,7,11,12
    }

    for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)
        for _, static in pairs(statics) do
            static:SetSolid(false)
        end
    end
end

I shall go through it step by step.

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

This block will call the SetStaticsSoftCollision() when the level starts (OnStart)

Code:

    local staticSlots = {
        0,2,4,5,6,7,11,12
    }

here. We store values in a table, these values represent static slots to be iterated later via loop (you can of course modify this to your case)

Code:

  
for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)
        for _, static in pairs(statics) do
            static:SetSolid(false)
        end
    end
end

Now here we do a nested loop (nested loops are loops that are inside a loop)

the outer loop

Code:

for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

traverses through the table and lets the engine know that these are static slots via GetStaticsBySlot

in the pairs() brackets you are passing staticSlots table variable for the loop to iterate through, the staticSlot is used to access the numbers in the table. You don’t need to worry about index variable as it just accesses the index of the number in the table so you don’t need to worry about it (index of digit 0 is 1, digit 2 is 2 and so forth).

note: if the index is never used/referenced then instead of index you can use an underscore _

hence from:

Code:

for index, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

will become:

Code:

for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

end of note

Code:

for _, static in pairs(statics) do
            static:SetSolid(false)

this inner loop will now loop through the statics variable to make them soft.

pairs(statics) loops through the table statics when we assigned them to GetStaticBySlot. we then reference each with static and setting them to soft collision static:SetSolid(false)

Setting soft collision using static’s lua name

The previous method is great because we can make every static in the slot to have soft collision. However, now you may ask: “But what if I DON’T want every static in the same slot to have soft collision? I want some of them to have hard collision.”

Well this is also doable:

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

function SetStaticsSoftCollision()

    local SoftCollisionStatics = {
        "static_mesh_433", 
        "static_mesh_399", 
        "static_mesh_398"
    }

    for _, value in pairs(SoftCollisionStatics) do
        local static = GetStaticByName(value)
        static:SetSolid(false)
    end
end

This code is very similar to our previous code for slot. However one difference is that instead of static slots numbers (2,4,50 etc) we are now using static’s lua name set in Tomb Editor and put them into the table and we only need one loop.

note: the strings must be comma separated as you see in the above example

(to change object’s lua name: right-click on the object -> rename object -> type the lua name you want the object to have for example: “static_mesh_5” to “wooden pedestal”)

Thanks for reading the tutorial 

references:
– https://lwmte.github.io/2%20classes/…tatic:SetSolid
– https://www.trlevel.de/lexicon/index…tatics-setzen/

Turning on Soft Collision for static objects and vice versa

(Based on l.m.’s tutorial from trlevel.de https://www.trlevel.de/lexicon/index…tatics-setzen/ code credit goes to him)

Tomb Engine has a default hard collision on for all statics. However, there may be cases where you just want to have some statics have soft collision. Well there are 2 ways to achieve this:

– Setting soft collision using static slots
– Setting soft collision using static’s lua name set in Tomb Editor

I shall go through the 2 methods.

you will need:
– basic understanding of array (in Lua they are called tables)
– basic understanding of loops (especially nested loop, more on that later)
– basic understanding of pairs() function.
– Static:SetSolid() command (https://lwmte.github.io/2%20classes/…tatic:SetSolid)

again if you don’t know anything about the arrays, loops etc then I recommend you to read the tutorial: https://github.com/Stranger1992/Tomb…a-Basics-Guide

Setting soft collision using static slots

the whole code is as follows:

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

function SetStaticsSoftCollision()
    local staticSlots = {
        0,2,4,5,6,7,11,12
    }

    for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)
        for _, static in pairs(statics) do
            static:SetSolid(false)
        end
    end
end

I shall go through it step by step.

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

This block will call the SetStaticsSoftCollision() when the level starts (OnStart)

Code:

    local staticSlots = {
        0,2,4,5,6,7,11,12
    }

here. We store values in a table, these values represent static slots to be iterated later via loop (you can of course modify this to your case)

Code:

  
for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)
        for _, static in pairs(statics) do
            static:SetSolid(false)
        end
    end
end

Now here we do a nested loop (nested loops are loops that are inside a loop)

the outer loop

Code:

for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

traverses through the table and lets the engine know that these are static slots via GetStaticsBySlot

in the pairs() brackets you are passing staticSlots table variable for the loop to iterate through, the staticSlot is used to access the numbers in the table. You don’t need to worry about index variable as it just accesses the index of the number in the table so you don’t need to worry about it (index of digit 0 is 1, digit 2 is 2 and so forth).

note: if the index is never used/referenced then instead of index you can use an underscore _

hence from:

Code:

for index, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

will become:

Code:

for _, staticSlot in pairs(staticSlots) do
        local statics = GetStaticsBySlot(staticSlot)

end of note

Code:

for _, static in pairs(statics) do
            static:SetSolid(false)

this inner loop will now loop through the statics variable to make them soft.

pairs(statics) loops through the table statics when we assigned them to GetStaticBySlot. we then reference each with static and setting them to soft collision static:SetSolid(false)

Setting soft collision using static’s lua name

The previous method is great because we can make every static in the slot to have soft collision. However, now you may ask: “But what if I DON’T want every static in the same slot to have soft collision? I want some of them to have hard collision.”

Well this is also doable:

Code:

LevelFuncs.OnStart = function() 
    SetStaticsSoftCollision()
end

function SetStaticsSoftCollision()

    local SoftCollisionStatics = {
        "static_mesh_433", 
        "static_mesh_399", 
        "static_mesh_398"
    }

    for _, value in pairs(SoftCollisionStatics) do
        local static = GetStaticByName(value)
        static:SetSolid(false)
    end
end

This code is very similar to our previous code for slot. However one difference is that instead of static slots numbers (2,4,50 etc) we are now using static’s lua name set in Tomb Editor and put them into the table and we only need one loop.

note: the strings must be comma separated as you see in the above example

(to change object’s lua name: right-click on the object -> rename object -> type the lua name you want the object to have for example: “static_mesh_5” to “wooden pedestal”)

Thanks for reading the tutorial 

references:
– https://lwmte.github.io/2%20classes/…tatic:SetSolid
– https://www.trlevel.de/lexicon/index…tatics-setzen/