Making liquid effects in the Torque Mission Editor
by Alonzo · in Artist Corner · 10/15/2006 (2:26 am) · 1 replies
I'm working on a fantasy game and want to know how to do liquid effects in the F11 editor, as well as some ideas on how to reduce the player's HP on contact. Any and all help and info is welcome.
Torque Owner Tod Kuykendall
1) In WorldEditor select WaterBlock from the SimGroup list and check the variables that you can manipulate underneath. Just about every aspect of the water's look and behavior can be modified.
2) As for damage the routines for damage for liquid contact exist in Torque. The implementation in starter.fps was a little buggy in 1.4 but the following changes will make it work.
There are several "%obj" variables in Shapebase damage routines that need to be "%this" instead. Swap these until your code looks like this:
//----------------------------------------------------------------------------- function ShapeBase::setDamageDt(%this, %damageAmount, %damageType) { // This function is used to apply damage over time. The damage // is applied at a fixed rate (50 ms). Damage could be applied // over time using the built in ShapBase C++ repair functions // (using a neg. repair), but this has the advantage of going // through the normal script channels. if (%this.getState() !$= "Dead") { %this.damage(0, "0 0 0", %damageAmount, %damageType); %this.damageSchedule = %this.schedule(50, "setDamageDt", %damageAmount, %damageType); } else %this.damageSchedule = ""; } function ShapeBase::clearDamageDt(%this) { if (%this.damageSchedule !$= "") { cancel(%this.damageSchedule); %this.damageSchedule = ""; } }NOTE: If you don't fix the "clearDamageDt" as well the water becomes like poison - once you touch it you will take damage -even after you leave the water - until you die. An interesting idea for enchanted or stagnant water maybe...Now that the underlying code works you need to set the code in player.cs to deal damage. There are Lava variables in the code but the syntax for calling in 1.4 is slightly different. Set a damage amount in beginning of the code - 0.1 is enough to get someone's attention but will give them a chance to get out.
Then add the call to the damage routine. For whatever reason the water in starter.fps is ocean water (I had echo to find this out) so you need to set the damage here.
function Armor::onEnterLiquid(%this, %obj, %coverage, %type) { switch(%type) { case 0: //Water case 1: //Ocean Water %obj.setDamageDt($DamageOceanWater, "Water"); case 2: //River Water case 3: //Stagnant Water . . . } }Now when you splash in the water you will take damage but it will stop when you leave it. If you want to only take damage when you are under water like drowning that is more complicated but the "enterLiquid" routine does return a percentage in water variable that can be used to tell how deep you are in the water. The swimming resources probably have details for that kind of stuff.
=Tod