Game Development Community

Does lightning work in 3.5.1?

by Joseph Mueller · in Torque 3D Beginner · 04/29/2014 (10:52 am) · 6 replies

Has anyone gotten it to work? When I add lightning, the thunder sounds off, but there are no flashes anywhere. It used to work for me back in Torque 2.0.

#1
04/29/2014 (3:43 pm)
T3D never supported the POSTFX flashes; or screenspace lightning. There is a shader that does that but by default the lightning will render a bolt via (I think randomly drawn vector).
#2
04/29/2014 (4:01 pm)
Hello J. Mueller,


https://dl.dropboxusercontent.com/u/64612150/lightning.jpg


It seems to me that is working fine, either the lightning or sound of thunders. The image above is showing the lightning in action, but no stormy clouds, though.

By the way, the grenade projectile in Torque 3D version 3.5.1 still not bouncing as in its earlier versions, that is, the issue it has not been fixed as announced on its release.

Greetings,
#3
04/29/2014 (5:28 pm)
I am using thunder and lightning for my project without issues in 3.5.1

Do note that the thunder is set to only be active in a set area so if you are on the other side of the terrain you will hear the thunder but won't see the lightning at all until you get the camera/player over to that area or have a clear view.

I suggest you use orbit mode and set your lightning to 60 strikes per min then fly up and see if you can see where the lightning is actually set to strike i bet you will see it somewhere on the map :)

Also does anyone know how to have the lightning follow the player? it be nice if it was set to work anywhere in the map instead of a specific location
#4
04/30/2014 (12:38 am)
@Joao, may I ask, what are you using for a sky, scattersky? I'm using a skybox, maybe that makes a difference? @Nin-Nin, I tried doing what you said about going into orbit, but no luck. I also positioned the lightning right above my player, and still nothing. I hear thunder but see no lightning. I will check into some console warnings about shaders:

shader compiled with warning(s): C:UsersJoeDocumentsGitHubTorque3DMy ProjectsEmptyProjectgameshadersprocedural1e0ff87551bbd19b_P.hlsl(87,21-84): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them

I'm not sure if this is related. I began to get these warnings after I upgraded from 3.0 to 3.5.1 with Anis' DX9/DX11 Refactor. You could have the lightning follow the player by polling the player methodically in script to find his location, like this:

//Set your constants in prefs.cs, or change them
//dynamically somewhere in script:

$MAX_LIGHTNING_DISTANCE = 20; //You might have to experiment with the number
$LIGHTNING_ALTITUDE = 532; //Adjust to taste, might have to experiment. This should equal 20 units above player
$LIGHTNING_TIME = 2000;  //Time between polls. 2 seconds sounds about right


//Put this at the end in player.cs
updateLightning(%player, %lightning)
{
   %pos = %player.getPosition();
   %lightningPos = %lightning.getPosition();
   %lightningDist = VectorDist(%pos,%lightningPos);
   if(%lightningDist > $MAX_LIGHTNING_DISTANCE)
   {
      %newPos = getWords(%pos, 0, 1)@$LIGHTNING_ALTITUDE;
      %lightning.setTransform(%newPos@" 1 0 0 0";
   }
   schedule($LIGHTNING_TIME,0, "updateLightning", %player, %lightning);  //Poll the player every $LIGHTNING_TIME ms.
}
   
 //Put this in player.cs inside of function PlayerData::onAdd(%this, %obj)
 //This will start the polling when player enters game
 //If you start your lightning later in the game, you might have to move this 
 //to wherever you start the lightning from
 %lightning = theLightning; //Or whatever you name your lightning
 updateLightning(%obj, %lightning); //%obj is the player inside the onAdd function

I haven't tested this code, but it should work, the lightning should follow the player around, relocating itself above him when it starts to get out of range.

If I can't get the stock lightning to work, I might try to brew my own. Thanks all for the help!
#5
04/30/2014 (11:21 pm)
@Joseph Mueller,


Yes, it was scatter sky indeed. I have tested with sky box and the lightning effect has worked nice as well, as shown in the following video:


youtu.be/YFGru65SZvA

I tried to embed the video, but did not work, for some reason. Anyway here's the link case if you want to watch at it.

Regards,
#6
04/30/2014 (11:33 pm)
Thanks Joao. You did a real nice job on that video!