Hpl2:Tutorials:level editor:dynamic curtains

From Frictional Wiki
Revision as of 14:49, 9 July 2020 by Maintenance script (talk | contribs) (Upload from wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Dynamic Curtains

Summary

We can simulate the action of wind over curtains by using the plastic curtain from AMFP and the force function.

1. Get the files


You need a modified version of the curtains that better respond to force.
You can create your own version or just use the ones I already did in my mod. LINK

Note: If you want to create your own version, make sure its bodies respond properly to force
and behave correctly when moving, no lag, no weird things. Also remove collision with player.


The files for the curtains are inside /models/curtains

2. Place the curtains.


Put the curtains wherever you want but not touching the wall or each other.
Then resize its width all you want, remember the model is initially thin.
Note: Curtains_Dynamic_001.ent is transparent, the 002 is normal and the rest 003 and 004 are experimental copies, ignore those.

3. Write the code.

The code below starts a loop function that randomly pushes the curtains and plays the wind sound.

Open your script file and add the following line inside your OnStart() function:

WindLoop ( "" );

Now copy&paste this other function and it's ready.

void WindLoop  ( string &in rabbit )
{
        AddPropImpulse  ( "Curtain_1",   2,   0.5,   0, "Local" );
        PlaySoundAtEntity ( "", "TR_spooky_wind_whirl.snt", "Curtain_1", 0, false );
        AddTimer ( "", RandFloat (3,5), "WindLoop" );
}

That's the most basic way to do it using only one curtain, from here you can add all the curtains you want by copy&pasting the PropImpulse and PlaySound lines.
Don't forget to change the name of the curtain.
You can also change any given value -like the force- to get better results.

Extra Info

- The sound TR_spooky_wind_whirl.snt is the wind sound I used, you can use another one, remember to change the name in the function.
- "Curtain_1" is the name of my curtain, yours may be different.
- The original code in my mod is a little more complex, you may want to take a look.

Amn.-