673f949eea3f7

673f949eeb88a
3 Guests are here.
 

Topic: Yet another flashlight demo Read 5932 times  

673f949eec478ZylonBane

673f949eec527
Here's a proof of concept flashlight demo, implemented in Squirrel. Works by raycasting out from the player camera, then placing a dynamic light source where it hits. It's a little more complicated in practice, but that's the base principle. I've been posting about this over at the TTLG Editor's Guild, but it's really more relevant to SS2 than Thief, so I figured I'd share it here too.

https://www.youtube.com/watch?v=B2U7VqvQpBI

Code: [Select]
function OnBeginScript() {
SetOneShotTimer("flashlight", 0.5);
}

function OnTimer() {
if (message().name == "flashlight") {
// some constants
local maxDist = 60;
local minRadius = 3;
local maxRadius = 17;
local maxLight = 250;
local deg2rad = PI / 180;
local lightObj = GetData("flob");
local lastObjLit = GetData("lastObjLit");
// ensure flashlight object exists and ID saved
if (!lightObj) {
if (!Object.Named("flob")) {
lightObj = Object.Create("Marker");
Object.SetName(lightObj, "flob")
}
else {
lightObj = Object.Named("flob");
}
SetData("flob", lightObj);
SetData("lastObjLit", 0);
lastObjLit = 0;
}
// get camera position/facing
local pos = Camera.GetPosition();
local face = Camera.GetFacing();
local faceY = face.y * deg2rad;
local faceZ = face.z * deg2rad;
// find out if there's a surface within range
local testPos = vector();
testPos.x = pos.x + maxDist * cos(faceY) * cos(faceZ);
testPos.y = pos.y + maxDist * cos(faceY) * sin(faceZ);
testPos.z = pos.z + maxDist * sin(faceY - PI);
local hitPos = vector();
local hitObj = object();
local hitObjID = 0;
// return values: 0 nothing, 1 terrain, 2 object, 3 mesh
local rayHit = Engine.ObjRaycast(pos, testPos, hitPos, hitObj, 0, 0, lightObj, 0);
if (rayHit) {
// calc distance to impact
local v = (hitPos - pos);
local d = sqrt(v.Dot(v));
local lightRad = (maxRadius - minRadius) * (d / maxDist) + minRadius;
local lightBright = maxLight * (1 - (d / maxDist));
// step back from impact by radius of the light
local d2 = d - lightRad / 2;
// never position light behind player
if (d2 < 0) {
d2 = 0;
}
// calc actual light position
// (there's probably a better way to do this)
local lightPos = vector();
lightPos.x = pos.x + d2 * cos(faceY) * cos(faceZ);
lightPos.y = pos.y + d2 * cos(faceY) * sin(faceZ);
lightPos.z = pos.z + d2 * sin(faceY - PI);
// apply updated light params
Property.SetSimple(lightObj, "SelfLit", lightBright);
Property.SetSimple(lightObj, "SelfLitRad", lightRad);
Object.Teleport(lightObj, lightPos, face); // facing doesn't matter
// handle object lighting
// (objects often need some help due to vertex lighting plus low poly counts)
if (rayHit == 2) {
hitObjID = hitObj.tointeger();
// check for object focus change
if (hitObjID != abs(lastObjLit)) {
killObjLight(lastObjLit);
// don't mess with objects that already have Extra Light
if (Property.Possessed(hitObjID, "ExtraLight")) {
lastObjLit = -hitObjID;
}
else {
lastObjLit = hitObjID;
Property.Set(hitObjID, "ExtraLight", "Additive?", TRUE);
}
SetData("lastObjLit", lastObjLit);
}
if (lastObjLit > 0) {
// fade to target brightness
local curLum = Property.Get(hitObjID, "ExtraLight", "Amount (-1..1)");
// (lightBright / maxLight) / 2) is the target extra light
Property.Set(hitObjID, "ExtraLight", "Amount (-1..1)", curLum + (((lightBright / maxLight) / 2) - curLum) / 3);
}
}
else {
killObjLight(lastObjLit);
}
}
else {
// light didn't reach anything
Property.SetSimple(lightObj, "SelfLit", 0);
killObjLight(lastObjLit);
}
// again!
SetOneShotTimer("flashlight", 0.0333);
}
}

// remove extra light from last lit object
function killObjLight(lastObjLit) {
if (lastObjLit != 0) {
SetData("lastObjLit", 0);
if (lastObjLit > 0) {
Property.Remove(lastObjLit, "ExtraLight");
}
}
}

This script is just placed on the player object. No provision for turning it on or off.
673f949eec70d
This is great. :D
It's probably a minor implementation detail but it seems to me that the light isn't very strong up close and doesn't disperse enough over a distance.

673f949eec835voodoo47

673f949eec88b
and the more important question - can AIs be made to go investigate should they spot the light?
673f949eecc54
That's really good! Adding a few dark areas to the base game would be atmospheric (dark enough so you do need a torch, I mean), but if you do decide to make such a mod then please don't put make the dark areas too long, as it does get tedious. Shorter areas of darkness, as used in Doom 1 and 2, are better as it makes a good contrast to the normal visibility of other areas.

And please PLEASE don't either make the torch only last for twenty seconds then need a time off to recharge, and not like in The Suffering where you need to use batteries that only last for a minute or two before dying. Those two game-play limitations (the light needs time to charge up, and you need to find batteries that in use are very short lived) are both irritating rather than adding to the fun of their respective games.

Could you make it so your in-game character requires a hand to hold the torch, meaning that you can hold the torch even if your other hand is holding a pistol or wrench (or if the hand is empty, of course), but not if he's holding something that requires two hands? And instead of having to grab the torch from your inventory, could you activate and deactivate it by pressing a user defined key (as otherwise you might have to alter the UI to specifically allow you to place a one-handed object into either hand)?

The NPCs should also recognise the torch (both the bright glow of the torch itself, and the resultant light that shines on the wall/floor/etc, as evidence of an intruder. You could probably build on this, to add a new short term playing style to the game, I think. We could debate about how this would effect the various NPCs - some of the less intelligent NPCs might not notice or care about the circle of light even if it passes over them (the spiders and lower AIs, for example, as they wouldn't attache any importance to it) though of course if they saw the person holding the torch then they would attack).

More intelligent creatures might try to follow the circle of light (if they hadn't yet noticed the person and the torch that was casting the light) for a while, and perhaps this could be used to divert such enemies.

The more intelligent enemies would recognise the beam of light as coming from somewhere, and would look for the torch (and so the player).

Maybe later in the game you could find an infra-red filter for the torch, and special glasses that let you see in infra-red. That was, you could use the torch in dark areas, and many or all organics won't see the beam (or you, because of the darkness), though of course mechanicals can (for game-play purposes!). Walking quietly through a (short) dark area with clumps of sleeping or unaware organic enemies, and having to stop and move back or alter your route a little to avoid being touched by an awake, moving enemy (because if you touch it, then it will know you are there, and all of the others will know that something is somewhere close by, but not where), could be very tense indeed.

673f949eecefeZylonBane

673f949eecf5b
It's probably a minor implementation detail but it seems to me that the light isn't very strong up close and doesn't disperse enough over a distance.
The textures in the demo video are pretty much all dark grey, so even at full illumination they aren't going to look very bright. And, dynamic lights in Dark go through walls, so the larger the maximum radius, the greater the chance of weird visual artifacts. Even so, the current max spread is about the same as the original Half-Life flashlight.

673f949eed153ZylonBane

673f949eed1a5
and the more important question - can AIs be made to go investigate should they spot the light?
Maybe? I've never messed around with that sort of thing. I see there's an Engine Features/Suspicious property, but I have no idea how to fill it out.

673f949eed627ZylonBane

673f949eed684
Adding a few dark areas to the base game would be atmospheric (dark enough so you do need a torch, I mean), but if you do decide to make such a mod then please don't put make the dark areas too long, as it does get tedious.
Changing the lighting of the levels would require distributing modified maps, which would be insane.

Could you make it so your in-game character requires a hand to hold the torch, meaning that you can hold the torch even if your other hand is holding a pistol or wrench (or if the hand is empty, of course), but not if he's holding something that requires two hands? And instead of having to grab the torch from your inventory, could you activate and deactivate it by pressing a user defined key (as otherwise you might have to alter the UI to specifically allow you to place a one-handed object into either hand)?
Christ, no, I cannot add dual-wielding to the engine. Take your Ritalin.

There is nothing in the game's UI that supports toggling of any abilities. All equipment use is managed through the inventory equip slots. So if this were turned into a proper mod, there would have to be a flashlight "weapon" implemented.

673f949eed8a5sarge945

673f949eed902
I can see it being more useful as an implant rather than a weapon.

Something you switch out your secondary implant for occasionally in dark areas

673f949eedb72ThiefsieFool

673f949eedbc9
All you need to have toggling is to script the flashlight to turn on/off when used in the inventory and change its object icon to show the current state, some of the toggleable things in Fallout worked like this.

If there's no way to make the light suspicious directly then it could probably be made suspicious with a fake sound that can't be heard and that "minor interference" flag or something.

673f949eedc97ZylonBane

673f949eedcef
Oh yeah, that would work. A bit nonstandard for SS2 though.

I'd thought about using a suspicious sound, but that would mean AIs would be able to "hear" the flashlight without even seeing it.

673f949eedd79voodoo47

673f949eeddc2
not mentioning some AIs are deaf.

673f949eede53ZylonBane

673f949eedea2
Even implemented only visually, it would be pretty funny having security cameras react to a flashlight.
673f949eedf95
This might be a stretch, but maybe it would be possible to direct the torch with your mouse in use mode - and then limit use to that. So no running around with a torch in hand, but only stationary examination of dark spots and places.
Acknowledged by: datiswous

673f949eee224Vegoraptor

673f949eee276
So no running around with a torch in hand, but only stationary examination of dark spots and places.
You can move perfectly fine in use mode though, rebind some keys and you can even turn. Makes the idea even more interesting I'd say.

673f949eee329ZylonBane

673f949eee377
That might actually be possible... but would feel wayyy too SS1-like for me.

673f949eee407voodoo47

673f949eee453
which is probably not a good thing.

673f949eee50fThiefsieFool

673f949eee558
If you think frobbing it from inventory to turn it on and off is too awkward, you can always create a new binding, and set a key to "use_obj flashlight", that would be enough to have a key that toggles the flashlight on/off.
673f949eee668
My thought was that if you can run around with it, then it's a shitty weapon. But if you can only examine with it locally then it's a special tool. The limitation might make it better.
Acknowledged by: datiswous

673f949eee718ThiefsieFool

673f949eee761
Yeah I get you, I was thinking it would just be an item rather than something occupying one of your paper doll slots.

Makes me think of other slots could be used for illumination, glowing armor?

673f949eee921JosiahJack

673f949eee96b
Does SS2 have support for spot lights?  Or only point lights?

673f949eeebceunn_atropos

673f949eeec23
SYSTEM SHOCK 2 LASER TAG MULTIPLAYER!

673f949eeecd4ZylonBane

673f949eeed25
Dynamic lights can only be point source. Baked lighting supports spotlights.

673f949eeedd0sarge945

673f949eeee1a
I also really like the "only when stationary" light idea. I don't really know how it would be implemented though, or if it's even really possible. Also very SS1 like
3 Guests are here.
Hey, you. You're finally awake.
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
673f949eefdfb