[Behavior] Grid based sight

From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hey 00Rez. I've been playing with behaviour, but I can't quite get it to work. Could you have a look at where I could have been going wrong?

    http://dl.dropbox.com/u/1378330/gridProblem.capx

    The pertinent events are in the "Terrain" and "Player" event sheets I believe.

    I'm getting a check failure when I try to open I'm using the latest [r61]

  • > Hey 00Rez. I've been playing with behaviour, but I can't quite get it to work. Could you have a look at where I could have been going wrong?

    >

    > dl.dropbox.com/u/1378330/gridProblem.capx

    >

    > The pertinent events are in the "Terrain" and "Player" event sheets I believe.

    I'm getting a check failure when I try to open I'm using the latest [r61]

    Hey 00Rez. Reuploaded.

  • >

    > > Hey 00Rez. I've been playing with behaviour, but I can't quite get it to work. Could you have a look at where I could have been going wrong?

    > >

    > > dl.dropbox.com/u/1378330/gridProblem.capx

    > >

    > > The pertinent events are in the "Terrain" and "Player" event sheets I believe.

    >

    > I'm getting a check failure when I try to open I'm using the latest [r61]

    Hey 00Rez. Reuploaded.

    Fixed to what you need (I think.) I've noticed a rounding problem my end which I'll have to fix. Anyways, when you have a for loop for the sight you *must* use the CurPixelX/Y or CurGridX/Y on both sides to pull and place the correct values! Hope this makes sense! Another thing is this is grid based therefore all objects must be in divisions/multiples of whatever the tilesize is which is 32 in your case. I noticed you had an offset of 300 which placed the generated tiles wrong. I set this to 320 and this fixed it. When you check sight and choose "in pixels" all this means is the plugin works out the grid position for you.

    Hope this helps Cowtrix! Nice demo by the way!

    Fixed version

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Actually, in the actual program, the dirt is 32x32. About the destination out, in the demo project, its set to XOR. Your talking about the LightCell, right?

    Anyways, I fixed what you told me to fix, and it still doesn't work...

    Problem, Again

  • Actually, in the actual program, the dirt is 32x32. About the destination out, in the demo project, its set to XOR. Your talking about the LightCell, right?

    Anyways, I fixed what you told me to fix, and it still doesn't work...

    Problem, Again

    Ok sorry about that must have been zoomed out or something. Anyway I forgot to mention you need to set the for loop to seen rather than hidden this will sort out the opacity issue. Using hidden is inverted, so the cells' opacity are full or invisible, which is why it shows nothing. Before changing anything Toggle disable the opacity setter and preview this will show the LightCells that are created so you will get a better idea of how it works! One last thing is due to the whole grid based approach it's best to have everything snapped to the grid of whatever tilesize you are using in your case 32 pixels. This can be set in the properties of the Sight behavior and set with the snap to feature in construct!

    I hope this helps Bowiz <img src="smileys/smiley2.gif" border="0" align="middle">

  • You can use the Sight behavior expression Tilesize to get the Sight's tilesize which you can also set in the behavior properties. You can use this for cell based calculations e.g.:

    round(Mouse.X/Player.Sight.Tilesize) * Player.Sight.Tilesize

    Grid expressions:

    Sight: Grid

    O Height: Get the height in cells of the field of view grid.

    O Offset: (used but not useful I think)

    O Radius: Get the sight radius.

    O Tilesize: Get the grids tilesize.

    O Width: Get the width in cells of the field of view grid.

  • For some reason when I change the radius, nothing happens. Any ideas why?

    Oh, and I got it working with your last posts :)

  • For some reason when I change the radius, nothing happens. Any ideas why?

    Oh, and I got it working with your last posts :)

    How and what are you setting the radius to?

  • > For some reason when I change the radius, nothing happens. Any ideas why?

    > Oh, and I got it working with your last posts :)

    How and what are you setting the radius to?

    <img src="http://dl.dropbox.com/u/19078872/opacity.png" border="0" />

    Toggle disable this then change the radius to 10 and preview then change it back to 5 and preview. The way you set opacity is the problem no matter how big the radius is the opacity is reduced at a set distance.

  • When I disable it the radius gets really big, more or less the way I want it, but I didn't get what you said about the set opacity thing. I just copied from the example file. What I understood is that code makes it so that the opacity is set in relevance to its distance from the light source, but only up to a certain distance. Is this right? If so, how can I change what the restraint is?

  • When I disable it the radius gets really big, more or less the way I want it, but I didn't get what you said about the set opacity thing. I just copied from the example file. What I understood is that code makes it so that the opacity is set in relevance to its distance from the light source, but only up to a certain distance. Is this right? If so, how can I change what the restraint is?

    The equation I used for the opacity was a quick implementation.

    The radius say 5 is multiplied by the tile size which is default 32. This is the maximum distance at which the opacity would be 100 or 0 depending on how you blend the LightCell/Shadow. You need to gradually decrease/increase this as the distance decreases back to the centre. Plus a realistic light has more of a drop off than a linear reduction in intensity. There is a bit of math involved in producing a realistic light. Experiment.

    Quick and easy way: min(Distance from light to shadow cell / (Radius * Tilesize), 1) this produces a number between 0 and 1. To invert take this number from 1 then multiply by 100 to get a value you can assign to the opacity setting for the lightcell/shadow objects.

    Make sure you snap to the grid when placing the objects or it won't look right.

  • I managed to get it to work somewhat, but instead of being lightest at the center, its darkest. How do I invert it? I think you explained it in your last post, but I still don't really get it. Can you try and explain it as if your explaining to an imbecile?

    Here is the code for the opacity:

    Lightcell--->Set Opacity To min(distance(Sun.X,Sun.Y,Sun.Sight.CurPixelX,Sun.Sight.CurPixelY)/ (10 * 32), 1)*100

  • I managed to get it to work somewhat, but instead of being lightest at the center, its darkest. How do I invert it? I think you explained it in your last post, but I still don't really get it. Can you try and explain it as if your explaining to an imbecile?

    Here is the code for the opacity:

    Lightcell--->Set Opacity To min(distance(Sun.X,Sun.Y,Sun.Sight.CurPixelX,Sun.Sight.CurPixelY)/ (10 * 32), 1)*100

    Lightcell--->Set Opacity To 1 - (min(distance(Sun.X,Sun.Y,Sun.Sight.CurPixelX,Sun.Sight.CurPixelY)/ (Sun.Sight.Radius * Sun.Sight.Tilesize), 1)) * 100

    The 1 - inverts the opacity. The Sun.Sight.Radius and Sun.Sight.Tilesize are expressions and if you put them in you don't have to worry about changing them as it will automatically update.

  • That didn't work for me, but it doesn't matter. I found that if you change from Destination Out to Destination In (on the lightcell of course) it works perfectly fine.

    I know I have a lot of questions, but this thing has a ton of potential so I'm really trying to get the most out of it.

    So my next question is: How can you change the "core" size of the light? By default it seems that the light starts from a single block (and its full strength there) and gets gradually dimmer. The core is that single full brightness block. So how can I change it to be instead of 1X1 to be (for example) a 3X3 core?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)