Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Pages: [1] 2  All

Author Topic: Flashlight script  (Read 27023 times)

0 Members and 1 Guest are viewing this topic.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Flashlight script
« on: August 14, 2004, 12:51:29 PM »

This example project demonstrates a flashlight scripting in WME. You can set various parameters of the flashlight in the beginning of flashlight.script (you will find the script in the "flashlight" folder in the project below).


Usage:

1) in your scene, create a dummy region called "foreground" and move it to the very bottom of the node list in SceneEdit
2) attach the flashlight.script to your scene

Currently the script displays the light cone at the position of the mouse pointer, if you want to display it at a different position, change the coordinates in the Update() function call in flashlight.script.

You can change the flashlight graphics for example to have a semi transparent edge around the light cone etc.


Download the demo project: http://dead-code.org/download/demos/wme_flashlight_demo.rar (~950 KB)


Requirements:
- WME 1.2.044 or later
- WinRAR 3.0 or later to unpack the archive


« Last Edit: August 23, 2004, 05:41:51 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Flashlight script
« Reply #1 on: August 16, 2004, 11:54:45 AM »

Oh man, that is a slice of pure genius! ::thumbup

When I use a 120x120 tile and change the variables accordingly, there's been known to be a grey stripe appearing on the right side of the screen, then fading away. Something related to the refreshing of the tiles perhaps?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Flashlight script
« Reply #2 on: August 16, 2004, 12:09:02 PM »

When I use a 120x120 tile and change the variables accordingly, there's been known to be a grey stripe appearing on the right side of the screen, then fading away. Something related to the refreshing of the tiles perhaps?
Um, darn. Ok, you can try to change the two occurences of line:
for(var i = 0; i<=NumTilesWidth; i=i+1)

to:
for(var i = 0; i<=NumTilesWidth+1; i=i+1)

That might help (hopefully).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re: Flashlight script
« Reply #3 on: August 20, 2004, 07:55:14 PM »

Yep. It runs smoothly now!
Logged

SBOVIS

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 404
  • FORGET REALITY SURRENDER TO YOUR DARKEST DREAMS
    • View Profile
    • LIMBO of the LOST
Re: Flashlight script
« Reply #4 on: May 21, 2007, 01:53:56 PM »

Hi, I am using a 200x200 light and dark graphic, but I am getting problems with the dark area when the pointer gets to the bottom of my 1048x768 screen.

It basically starts to rise up a little then disappears when I move the pointer up, I can email images if needed?

Any ideas??
Logged
kind Regards
Steve Bovis
MAJESTIC STUDIOS

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Flashlight script
« Reply #5 on: May 21, 2007, 05:05:00 PM »

Add one more row of the dark tiles.

var NumTilesHeight = MainLayer.Height / TileHeight + 2;
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Orange Brat

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 112
    • View Profile
    • Orange Brat Shenanigans™
Re: Flashlight script
« Reply #6 on: May 21, 2007, 08:03:04 PM »

This reminds me of Alone in the Dark 4. Ever played it? It features prerendered backgrounds, but the character's flashlight can "light up" the darkened backgrounds. The cool thing is that it also creates shadows based off the flashlight's position, and they react appropriately to the flashlight. Would it be possible, in WME, to make the dynamic shadows react to the light cone?

You'd have to get the 3D coordinates based off the center point of the flashlight cone and trace from the player's world position to this vector in the level. Everything within the circular light cone would need to be influenced, of course.

I'm not sure right off the top of my head how to do this in WME, but what I described above is a start I suppose. There's a PC demo of the game floating around if you want to see the effect first hand. It's not the greatest game, but the effect is nice.

EDIT: Actually, I just played it, and it doesn't cast shadows, so I'm wrong about it. The flashlight is projected onto the walk plane, though and it lights up parts of the background it touches nicely. It looks like a real directx light because of an obvious tessellation effect.
« Last Edit: May 21, 2007, 08:27:16 PM by Orange Brat »
Logged
The Disenfranchised™ - coming later

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Flashlight script
« Reply #7 on: May 21, 2007, 08:57:25 PM »

Hmm, you can change the light position for shadow projection in a script, so I think it should be possible to some extent. In combination with the above script or with additive blending it might yield some interesting results.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Flashlight script
« Reply #8 on: May 22, 2007, 11:11:37 AM »

There are two background pictures for each scene in AITD4: a dark version and a lit version. The light cone is projected on a simplified version of the scene and the resulting image is used as a blend factor between the lit and unlit version. (Well, that's the basic idea but it couldn't work exactly like that on the PS1). The characters and monsters have simple shadows but on the PS1 and on the Dreamcast version they have stencil buffer-type shadows. I don't remember what light source is used for these stencil shadows, though.

But I remember seeing a trailer for this game in early 2000 where the light cone intersects with a pillar in a room and the pillar projects a shadow onto the environment. This was all done in 3DS MAX but rendered with no texture filtering so as to look like PS1 real-time rendering... Maybe that's what confused you ;)

Anyway, the main difference here is that the light cone is projected in 3D, and I don't think that's the case in this flashlight demo, unless I missed something.
Logged
I am the Milkman. My milk is good.

Orange Brat

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 112
    • View Profile
    • Orange Brat Shenanigans™
Re: Flashlight script
« Reply #9 on: May 23, 2007, 05:11:59 AM »

I only played it on PS2, and the demo I mentioned above is the PC version. I never saw the PS1 version. I now remember reading an interview talking about the use of two backgrounds. I guess they faked the perceived dynamic shadows on the backgrounds then.
Logged
The Disenfranchised™ - coming later

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Flashlight script
« Reply #10 on: May 23, 2007, 09:47:08 AM »

Well on the DC version (which served as a basis for the PS2 and PC versions) the characters' and monsters' shadows are projected to the simplified model for the background. Or maybe on a separate model ? I can't remember, it's been quite a while. But WME is getting close to the techniques that were used in AITD4 now that you can define "shadow" planes in the 3DS collision files and have simplified models for actor shadows.
Logged
I am the Milkman. My milk is good.

Dan-D

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Flashlight script
« Reply #11 on: August 16, 2007, 08:37:10 PM »

I dont get it. It's possible to create AITD4 like flash light or not?
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Flashlight script
« Reply #12 on: January 17, 2012, 07:17:45 AM »

Sorry I know this post is really old, but I need some help. Im designing sort of a puzzle mini game and I have been using this script. Is there a way to make the flashlight stay transparent on the locations the mouse moves too? For example, if you start the game and move the mouse down, everywhere the mouse touches will stay lit and not go away. I was thinking maybe just making one big black image instead of tiling them, or maybe the tiled entities get deleted when the cursor moves over them. If anyone can help, let me know :)    Many thanks !!
Logged

Endrit

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 62
    • View Profile
Re: Flashlight script
« Reply #13 on: January 17, 2012, 03:43:40 PM »

nice idea !
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Flashlight script
« Reply #14 on: January 17, 2012, 04:33:40 PM »

Any suggestions Mnemonic ?
Logged
Pages: [1] 2  All
 

Page created in 0.024 seconds with 24 queries.