Flashlight Offset.

Have any questions or problems in making your game, subscribing and/or using our software? Post here.
Forum rules
Make sure you are using the newest version. This can be downloaded at the top of the site via the "downloads" link.

Use a very good subject. "Problem" or "Help" are unacceptable titles.

Use the search feature before posting a question, as the answer is probably already here.

Subscript out of range error 9: This is a generic error, and we'll need way more information than that to figure out the problem. If you get this, strongly consider following the instructions of submitting your project through the Submit Bug feature within the editor.
User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Flashlight Offset.

Postby Tabula Rasa » Wed Apr 30, 2014 2:27 am

I'm trying to make a flashlight operate like more of a flashlight. Is there a way to offset the light source so that it appears a meter or two ahead of where the player is facing?
Image

User avatar
Gamerdude
001 Support
 
Joined: Wed Dec 12, 2007 8:56 pm
Location: Australia

Re: Flashlight Offset.

Postby Gamerdude » Wed Apr 30, 2014 6:07 am

Yeah. You'd just have to check which way the character is facing, then use a Position Light event to position it to the Player's X/Y +32/-32 depending on which way they're moving. Might be funky for when you approach a wall though.
Image
Image

User avatar
Mike
001 Co-Founder
 
Joined: Sun May 08, 2005 1:29 pm
Location: Ontario, Canada

Re: Flashlight Offset.

Postby Mike » Wed Apr 30, 2014 9:17 am

Something that seems to never come up is the "Direction Point X/Y" use values. Given a starting location and a direction, you can extend out to a point at a certain distance away. You'll need to use both and deal with X and Y independently - it isn't very hard though. If you think your code is modular enough and you're able to implement this portion easy enough, you should post this part of your script so others can learn from it.

User avatar
Dunce
001 Forum Master
 
Joined: Sun Apr 08, 2007 3:33 am
Location: Arkansas, USA

Re: Flashlight Offset.

Postby Dunce » Wed Apr 30, 2014 2:17 pm

Huh, never knew there was usevalues like that.
Image

User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Re: Flashlight Offset.

Postby Tabula Rasa » Sun May 04, 2014 10:16 am

I've tried it, and so far it's working out pretty well. One problem; the light has a tendency to completely disappear into the wall. Anyway to detect collision via scripting?
Image

User avatar
Mr.Numbers
001 Support
 
Joined: Wed Feb 28, 2007 1:50 am
Location: Alberta, Canada

Re: Flashlight Offset.

Postby Mr.Numbers » Sun May 04, 2014 6:35 pm

There are a few ways of doing this, some of which may be more efficient than others.

I'd try using the "Line Collision Branch", or check for tile-sets (Check if the tile is a wall). If it does collide or is a wall or whatever, you could try positioning the light closer to the actor and keep looping until the light is literally at the actors x/y location. (In which case, unless you're inside a wall, it shouldn't cause an infinite loop probably)
Image
I AM THE ALL MIGHTY SCRIPTING MASTER
Please do not PM me with Engine 001 related questions, rather post on the forums. ;)

User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Re: Flashlight Offset.

Postby Tabula Rasa » Mon May 05, 2014 10:50 pm

Yeah, the Line Collision Branch doesn't check for tiles, it checks for Actors.
Image

User avatar
Mike
001 Co-Founder
 
Joined: Sun May 08, 2005 1:29 pm
Location: Ontario, Canada

Re: Flashlight Offset.

Postby Mike » Mon May 05, 2014 10:51 pm

No, it should. It's what the lighting system uses.

User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Re: Flashlight Offset.

Postby Tabula Rasa » Mon May 05, 2014 11:03 pm

Trying it, no matter what I do or how I script it, the line collision branch returns a positive result, even if it's an empty map with no walls or actors. The distance is set via variable to only 150 pixels in front of the character.

Image

User avatar
Mr.Numbers
001 Support
 
Joined: Wed Feb 28, 2007 1:50 am
Location: Alberta, Canada

Re: Flashlight Offset.

Postby Mr.Numbers » Mon May 05, 2014 11:48 pm

When you say "True", does that mean the left path? (Aka "Collides")
Perhaps try using a Z value of something other than 0 maybe?

Another little point - I'd put a comparison branch checking if collision = 0, if it does, place the light on the actor or something.
Image
I AM THE ALL MIGHTY SCRIPTING MASTER
Please do not PM me with Engine 001 related questions, rather post on the forums. ;)

User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Re: Flashlight Offset.

Postby Tabula Rasa » Wed May 07, 2014 12:55 am

The script already does that the way it is. It could possibly infinitely loop if the player is stuck in a wall, but otherwise it should be fine.

BUMP: Found the issue; the Line Collision branch was colliding with the player. Offset it so that the line starts approximately 16 pixels away from the player, now it works fine. The scripts works via a timer in the HUD if anyone is interested.

Image

User avatar
Dunce
001 Forum Master
 
Joined: Sun Apr 08, 2007 3:33 am
Location: Arkansas, USA

Re: Flashlight Offset.

Postby Dunce » Wed May 07, 2014 2:45 am

You should be able to ignore "main", instead.
Image

User avatar
Mike
001 Co-Founder
 
Joined: Sun May 08, 2005 1:29 pm
Location: Ontario, Canada

Re: Flashlight Offset.

Postby Mike » Wed May 07, 2014 9:53 am

Dunce wrote:You should be able to ignore "main", instead.

+1

User avatar
Tabula Rasa
001 Forum Master
 
Joined: Sun Jul 20, 2008 11:36 pm
Location: A place between mind and matter.

Re: Flashlight Offset.

Postby Tabula Rasa » Wed May 07, 2014 12:15 pm

Silly me, forgot about that. :P Well, here's the final draft. Added a neat little feature where the light will gradually get smaller as you get closer to a collision object.
______________________________________________

Image

EFFEKT Records
Member
 
Joined: Fri Aug 26, 2016 4:56 am

Re: Flashlight Offset.

Postby EFFEKT Records » Tue Nov 22, 2016 1:06 am

What about the floor, I've used this and its working great! and glad I came upon it, but when I look to the floor there is no light.


Return to Technical Support Questions

Who is online

Users browsing this forum: No registered users

cron