PDA

View Full Version : How to make rectangular sensor areas!



Treas
10-07-2009, 11:00 PM
Most of you will know that the "Camera Tool" has got a rectangular activation area, as opposed to proximity and mag switches which do only feature a circular area.

A while ago, I thought it would be quite useful at times if we had the option to set a rectangular radius for all our switches. Well, I didn't give it much thought at that time.

It was tonight when I suddenly needed said feature and started playing around with the proximity switch. And I did indeed find a most thermo-friendly and simple solution. Some logic- and tech-interested people (like me) here on LBPC will probably already have figured this out by now, but I'll post this tutorial for all who might be interested in this technique. It's really not much of a big deal. I've done some screenshots, but I don't think I'm even going to need them here.

Ok, so in order to use this, you'll have to understand the basic concept: What we want to do is creating a rectangular "area". This is not possible using only one single proximity switch. So, let's think of it: How could we create a rectangular shape by ourselves? the closest thing to a rectangle you can get is a quarter circle. So, how do we get a rectangle? The following sketch might give you a clue:



http://www.abload.de/img/demicircleg2d8.png

See the astounding simplicity? Basically, all you have to do is setting up 2 proximity switches, each angled at 45 degree and with a radius of 90 degree (one turned by 180 degree), so that their right-angled sides form a rectangle. Just change the positions of the two switches (but make sure that each switch is positioned within the activation area of the other one) in order to create every possible rectangular shape.

Next step: Create an AND gate (http://www.lbpcentral.com/forums/blog.php?b=411) and link your two proximity switches up to that gate (so that the output only gets activated when both of them are active at the same time, which means that a player has to stand in the rectangular area). You're done! Simple, wasn't it?

This same technique does also apply to magnetic switches. All you need are two switches and an AND gate.

Of course, using the same basic idea - connecting multiple switches with different activation areas using any logic system - you can create nearly every shape you could imagine. Oval, hexagon, L-shape - anything is possible. Just use your imagination and a fitting set of AND, OR and whatever else you may need.

Update 11.10.09

Actually, you can create any desired shape using this technique. Here's a few simple guidelines as for which logic gate fits which needs:

Note: I always use a set of 2 sensors for the examples below. "N" stands for normal state, "I" stands for inverted state. [NI], for example, means that the left sensor (represented by the left circle) has to be normal whereas the right sensor has to be inverted.

Intersection: AND Gate [NN]
(Multiplayer: Require All)

http://www.abload.de/img/schnittmengen6eg.png

Set Union: OR Gate [NN]
(Multiplayer: NO Require All)

http://www.abload.de/img/vereinigungsmengew6a6.png

Difference Quantity: AND Gate [NI]
(Multiplayer: Normal: Require All, Inverted: NO Require All)

http://www.abload.de/img/differenzmengex6yn.png

Complementary Set: XOR Gate [NN]
(Multiplayer: not reliable)

http://www.abload.de/img/komplementrmenge1691.png

Of course, you can combine any desired amount of sensors (at any angles) and as many gates as you want. This allows you to create pretty much any shape you could ever dream of.


Hope this helped :)

Silverleon
10-07-2009, 11:25 PM
Tho technically you only need one of them as both switches cover that area...

Treas
10-07-2009, 11:36 PM
I don't quite get your point. You mean that you only need one sensor switch to form a perfect rectangular detection area? If so, how would you do this?

Burnvictim42
10-07-2009, 11:43 PM
Thats a pretty smart idea for making a very defined sensor area. I'm not entirely sure where i would need it though... could i get an example?

rtm223
10-07-2009, 11:46 PM
Which room is sackboy in?

adlingtont
10-07-2009, 11:52 PM
It's all so simple now! Thanks for this!

Treas
10-07-2009, 11:53 PM
Did I forget to mention that you can change position, length and width of the rectangle in real-time by just attaching the sensors to movable surfaces?

You could, for example, create a survival challenge where the player does always have to fly (or swim, yay!) within the boundaries of a certain frame of laser beams. This would require exact detection lines, as a player wouldn't want to get killed just because he got near a laser, not even touching it.

Just a quick idea though, and I'm sure there's lots of uses for it.

rtm223
10-07-2009, 11:59 PM
A note on "exact detection lines":

They aren't. On a small scale the sensors generally are accurate enough, but on a larger scale both the curved and straight edges aren't exactly where you think they are.

It's hysteresis, for those who are familiar with the term. If not it's probably just easier to make sure you test it thoroughly.

Gilgamesh
10-08-2009, 12:02 AM
Simple and effective, I like it. :)

I might find a use for a system like this in the future, so I'll be sure to keep it in mind.

Treas
10-08-2009, 09:26 AM
It's hysteresis, for those who are familiar with the term.

Jup. Did some intense testing on the activation radius and it definitely is hysteresis. But the inner and outer limits are quite close together. Lies around 1-2.5, to put it in LBP measurements. So, the maximum divergence is one small grid block. Plus, sackboy's head doesn't count towards collision or sensor area detection.

I did some tests and found that my rectangular areas deliver more precise results in spite of hysteresis. Plus, it is especially useful if you want a "dynamic" range (described in my last posting).

rtm223
10-08-2009, 09:41 AM
I thought that on large scale sensor areas it was massive? Either that or there is a huge discrepancy between the graphics for the detection zone and the actual detection zone. BTW I'm not saying that the rectangular areas are less precise, it's the fact that the sensors themselves are imprecise and don't trust those graphics :grr:

Treas
10-08-2009, 01:30 PM
I know. The "blurry", fading outline of the sensor area itself already tells us about the massive lack of precision. The discrepancy does indeed get bigger, but my no means proportional to the size of your detection area. I haven't yet figured out any exact measurement, seems to be quite a piece of difficult code behind that. Still, it's precise enough for most tasks, so I'm not too frustrated about them right now.

robotiod
10-08-2009, 01:35 PM
That s a great idea once i saw the diagram i figured it out straight away its pretty simplae actually, This idea could go further if you need it even more precise with three or four sensor switches but its not quite needed.

springs86
10-08-2009, 01:37 PM
That looks awesome, if i build another level, i'm gona put this in it somewhere, thanks :)

Foofles
10-08-2009, 01:42 PM
Great post! I never imagined having to use a quad shaped sensor area, but you make perfect sense.

This would also be great on doors and springboards since the spread is much more even and predictable.

robotiod
10-08-2009, 01:50 PM
If you think cleverly about it you could make a tine exact point were sackboy must be by using 2 sensors with angle set to one so it would be really presice

wexfordian
10-08-2009, 01:51 PM
I was just thinking about this last night actually so its weird to see you have posted it here today :) Although the solution I came up with was using 4 switches, one on each corner so yours is twice as elegant a solution. What I was thinking of using this for is having an exact positioning system for players in the air (or water). If you were to build a grid of these sensors then you can pinpoint the player on the screen. knowing that of course can lead to some really interesting possiblilities.

robotiod
10-08-2009, 01:53 PM
I was just thinking about this last night actually so its weird to see you have posted it here today :) Although the solution I came up with was using 4 switches, one on each corner so yours is twice as elegant a solution. What I was thinking of using this for is having an exact positioning system for players in the air (or water). If you were to build a grid of these sensors then you can pinpoint the player on the screen. knowing that of course can lead to some really interesting possiblilities.

What your getting into here is like big brother, The level knowing exactly were you are at any one time, make a tracking system that follows sackboy anywere and you have pretty much full control of there path. Now how this would be helpful would be well above a normal creators level but imagine fully interactable character and stuff like that.

wexfordian
10-08-2009, 01:56 PM
What your getting into here is like big brother, The level knowing exactly were you are at any one time, make a tracking system that follows sackboy anywere and you have pretty much full control of there path. Now how this would be helpful would be well above a normal creators level but imagine fully interactable character and stuff like that.

Now were thinking along the same lines :)

Treas
10-08-2009, 02:33 PM
If you think cleverly about it you could make a tine exact point were sackboy must be by using 2 sensors with angle set to one so it would be really presice

Forget the "Angle set to one". As rtm223 has already pointed out, the positioning of the actual sensor area doesn't exactly match the displayed, blurry outlines: The area of effect changes everytime it is triggered or untriggered. It's like chewing gum, to put it simple: When you move out of a sensor area, it will "stretch out" a little bit and follow you, expanding a little. When you step in again, it will "stretch back" with your movement. This effect isn't really noticeable when you move fast, but experiment with small mag keys and switches and you'll see it.

This does also apply to tight-angled mag switches: Angles below 10 degree tend to get buggy. Sometimes, they activate way before the given object enters the area, and at other times, you can drop a mag key right through the detection area and the switch wouldn't even activate.

Be careful with 1 degree angles :)

comphermc
10-08-2009, 03:00 PM
I don't think it has been mentioned yet, but deftmute came up with a great way to give precise angles to the placement of sensor switches. He considered it for 90 degrees (perfectly sideways), but it can be extended to make sure your sensor switches are at exactly 45 degrees when you place them (allowing for a perfect square).

Get out the right triangle shape and drop your sensor switch on it. Turn off grid mode and butt the long side of the right triangle up against a flat horizontal or vertical surface until you get a clean 45 degree angle for the sensor switch in the desired direction. Then, copy the sensor switch (do not detach it - it will automatically realign to default angle), and place it as desired. Boom! Perfect 45 degree angle placement.

-----

Also, I have been using something similar to this to achieve more accurate searchlight player sensing that might be of use. You know how when using a searchlight, trying to tweak the angle and distance is quite a hassle? What I do is tweak the the trigger area for a searchlight to be a huge circle that covers way more area than necessary. Then I put a sensor switch in the area where I want the player to activate the "Logikz". Wire the searchlight and the sensor switch through an AND gate and you are finished. This allows more precise, layer specific sensor switch activation.

This has come in handy several times now.

:)

ZramuliZ
10-08-2009, 08:06 PM
Also, I have been using something similar to this to achieve more accurate searchlight player sensing that might be of use. You know how when using a searchlight, trying to tweak the angle and distance is quite a hassle? What I do is tweak the the trigger area for a searchlight to be a huge circle that covers way more area than necessary. Then I put a sensor switch in the area where I want the player to activate the "Logikz". Wire the searchlight and the sensor switch through an AND gate and you are finished. This allows more precise, layer specific sensor switch activation.

That's a nice solution but I see one problem:
http://dl.getdropbox.com/u/1267706/switchError.jpg
So if player 1 is in the layer of the spotlight and player 2 is in radius of the prox switch, the logic will be triggered even if player is not in the desired area. This makes things trigger too early.

rtm223
10-08-2009, 08:38 PM
Get out the equilateral triangle shape and drop your sensor switch on it. Turn on grid mode and rotate the equilateral triangle until you get a clean 45 degree angle for the sensor switch in the desired direction. Then, copy the sensor switch (do not detach it - it will automatically realign to default angle), and place it as desired. Boom! Perfect 45 degree angle placement.


Perfect, within a tolerance of 15 degrees :rolleyes: What you really want to do is put it on a right-angled triangle and then with grid mode OFF, butt it up against the floor or a vertical wall. That is how you get 45 degree angles. They stopped teaching sums in your maths lectures comphy?


@Zramuliz - this is true, and it would also affect the method in the OP. However, Wex's solution does not suffer from this. It depends how 2 player safe you need to be vs thermo considerations.

Of course you can make a "require all" box using treas's solution, by setting both proxes to require all.

RangerZero
10-08-2009, 10:09 PM
It's an excellent idea, but just to bring some useless bull on the table, it's impossible to have a rectangle. Why? It's 2 quarters of a circle. This only creates squares :P

.

comphermc
10-08-2009, 10:19 PM
Perfect, within a tolerance of 15 degrees :rolleyes: What you really want to do is put it on a right-angled triangle and then with grid mode OFF, butt it up against the floor or a vertical wall. That is how you get 45 degree angles. They stopped teaching sums in your maths lectures comphy?

Lol, I guess so. I will edit that now.


That's a nice solution but I see one problem:

[Picture]

So if player 1 is in the layer of the spotlight and player 2 is in radius of the prox switch, the logic will be triggered even if player is not in the desired area. This makes things trigger too early.

Require All? (on both of them) I have used this in a level that works for multiplayer, so I know it works.

rtm223
10-08-2009, 10:32 PM
It's an excellent idea, but just to bring some useless bull on the table, it's impossible to have a rectangle. Why? It's 2 quarters of a circle. This only creates squares :P

.


You may wanna go back and take a closer look at the OP there buddy ;)

RangerZero
10-08-2009, 11:42 PM
You may wanna go back and take a closer look at the OP there buddy ;)

Ok, I missed the "AND switch" part. This indeed make so the area not in the rectangle will do nothing.

.

ZramuliZ
10-09-2009, 07:38 AM
Require all! That's it! Why I didn't think about it. *goes to fix own levels with this new info* :)

Kern
10-09-2009, 05:10 PM
wow thats awesome...

Treas
10-10-2009, 09:34 AM
Actually, you can create any desired shape using this technique. Here's a few simple guidelines as for which logic gate fits which needs:

Note: I always use a set of 2 sensors for the examples below. "N" stands for normal state, "I" stands for inverted state. [NI], for example, means that the left sensor (represented by the left circle) has to be normal whereas the right sensor has to be inverted.

Intersection: AND Gate [NN]

http://www.abload.de/img/schnittmengen6eg.png

Set Union: OR Gate [NN]

http://www.abload.de/img/vereinigungsmengew6a6.png

Difference Quantity: AND Gate [NI]

http://www.abload.de/img/differenzmengex6yn.png

Complementary Set: XOR Gate [NN]

http://www.abload.de/img/komplementrmenge1691.png

Of course, you can combine any desired amount of sensors (at any angles) and as many gates as you want. This allows you to create pretty much any shape you could ever dream of.

tru3_skitz0
10-10-2009, 07:48 PM
Wow thanks for this! U just gave me a great idea for my science lab survival challenge Ive been workin on. I cant wait to start messin with this concept. Truly helpful post. :)

Sunrise_Moon
10-10-2009, 09:11 PM
I added this to my Helpful Threads and Links thread (http://www.lbpcentral.com/forums/showthread.php?t=17342)! Good job!

Treas
10-11-2009, 02:38 PM
Thanks for all your feedback and inputs. And thanks to Sunrise_Moon for adding it to your thread!

I really enjoyed the vivid discussion which unfolded in this thread. Keep the good (tech and logic) vibes coming!

I've added the short set theory overview to the tutorial to keep things clean and tidy.

rtm223
10-12-2009, 12:06 PM
You might want to add a section on the multiplayer limitations of these techniques. For example:

AND: Only works sensibly / reliably as a "require all"
OR: Only works sensibly / reliably as NOT "require all"
Difference Quantity: Won't work in multiplayer.
XOR: Won't work in multiplayer.

By won't work, I mean that the behaviour does not accurately match a "any player in the area" or "all players in the area".

Treas
10-12-2009, 12:12 PM
Thanks for the addendum, rtm! I'll add that to the tutorial.

Rogar
10-13-2009, 12:46 PM
Difference Quantity: Won't work in multiplayer.
XOR: Won't work in multiplayer.

Good point, but the last two aren't true. You can say all players are in area A (require all) AND none are in area B (require any, inverted) for the difference (reliable only as require all). For XOR, you are right it won't work straight up, but there are some possibilities, depending on what you want (who wants such a weird sensor area anyway ;) ).

Let's just say you have to be extra mindful of multiplayer. As always.

rtm223
10-13-2009, 01:26 PM
Very true, I missed that combination for difference quantity. Good spot

Treas
10-13-2009, 01:34 PM
Nice :) I'm in a bit of a hurry at the moment, gonna update the tutorial as soon as I find some spare time.

srgt_poptart
10-14-2009, 11:52 PM
Really smart, I was developing a concept just like this one, but it used 4 sensor switches. I noticed the blurry outline once when creating, and you had to go all the way past to the blur to activate the sensor switch, and all the way out to de-activate it, which generally creates 2 separate lines, one for entry and one for exit.

comphermc
10-14-2009, 11:56 PM
Really smart, I was developing a concept just like this one, but it used 4 sensor switches. I noticed the blurry outline once when creating, and you had to go all the way past to the blur to activate the sensor switch, and all the way out to de-activate it, which generally creates 2 separate lines, one for entry and one for exit.

Yup, I believe rtm223 called it hysteresis. He's too smart sometimes. That's exactly what is happening, and it's pretty frustrating at times...

Treas
10-15-2009, 04:56 PM
Hysteresis can (and is even supposed to) be a good thing! It's a calculating method which should get rid of any kind of zig-zag movement around a certain limit. However, in LBP, it does clearly not fulfill its purpose. I haven't yet observed a single instance where it helped to get any device working. If you put a sensor switch (rotation 90 degree, angle radius 180 degree) on a wobble bolt and set it to directional, hysteresis should (or could, at least) achieve that the wobble bolt would not panick and have a seizure, but to lock on any sackboy and remain still. That's the basic purpose of hysteresis.

I think though that, if Mm decided to use hysteresis, they should at least give us the option of tweaking the value.

srgt_poptart
10-18-2009, 05:27 PM
Thats really good, but wouldn't it be a bit hard to see the actual rectangle, as you can only tweak one switch at a time? You could in theory just use another controller, but that might be a bit awkward.

srgt_poptart
10-18-2009, 05:32 PM
I used hysteresis in a level, as it was a component in a Player Tracking Device. (PTD)
It helped make it so that the piston would not move back and forth violently, like you said about the wobble bolt.

Treas
10-19-2009, 05:11 AM
Thats really good, but wouldn't it be a bit hard to see the actual rectangle, as you can only tweak one switch at a time? You could in theory just use another controller, but that might be a bit awkward.

Well, not really. I mean, imagining two straight lines going out from a visible source (the prox switch) isn't that hard. Plus, you can always work with stripes of material to mark the borderlines while you work on it. And I think the advantages (free-form dynamic rectangles etc) do clearly outweigh that issue.


I used hysteresis in a level, as it was a component in a Player Tracking Device. (PTD)
It helped make it so that the piston would not move back and forth violently, like you said about the wobble bolt.

I guess you've built some hysteresis logic yourself? I didn't yet get the hysteresis "add-on" on prox and mag switches to work in any useful way.

Rogar
10-19-2009, 12:54 PM
Hysteresis can (and is even supposed to) be a good thing! It's a calculating method which should get rid of any kind of zig-zag movement around a certain limit. However, in LBP, it does clearly not fulfill its purpose. I haven't yet observed a single instance where it helped to get any device working. If you put a sensor switch (rotation 90 degree, angle radius 180 degree) on a wobble bolt and set it to directional, hysteresis should (or could, at least) achieve that the wobble bolt would not panick and have a seizure, but to lock on any sackboy and remain still. That's the basic purpose of hysteresis.

I think though that, if Mm decided to use hysteresis, they should at least give us the option of tweaking the value.

I think the problem here is that while the sensors have hysteresis, the wobble bolt on direction can only go one way or the other, there's no input to stay still. So you have to work around that, maybe with a threeway switch?

Argon Vile
10-19-2009, 01:07 PM
I think the problem here is that while the sensors have hysteresis, the wobble bolt on direction can only go one way or the other, there's no input to stay still. So you have to work around that, maybe with a threeway switch?

It depends on the effect you're after. Treas didn't give a lot of details. If you want something like an object on a wobble bolt which points to the player - then I've had success using the setup you've described - one sensor switch pointing to each side, which pull on an offscreen 3-way switch. You can see the effect with the sackboy-tracking lights that appear in the first 10 seconds of this youtube vid, :

YouTube - LittleBigPlanet level Creete, a high-speed race

It still goes into zigzag mode sometimes (like the pink light does) but it's not the hysteresis thing as much as the inaccuracy/time delay of the 3-way switch mechanism. The lights appear later on in the level too, where the "zigzag" effect is less noticable because the player's moving faster.

Also, as Treas said, the hysteresis effect doesn't help this mechanism either :d

Treas
10-19-2009, 02:59 PM
I think the problem here is that while the sensors have hysteresis, the wobble bolt on direction can only go one way or the other, there's no input to stay still. So you have to work around that, maybe with a threeway switch?

You're completely right about that, and I do actually use three-way switches for all such contraptions. Still, I'm really curious if anyone found an actual use for the built-in hysteresis...

srgt_poptart
10-19-2009, 11:41 PM
I didn't use the built-in hysteresis, as it is much too small to be any use at all. I just put too sensor switches bottom to bottom, but instead of making the angle 180 degrees, I made it 160, so there is a space in the middle.

rtm223
10-19-2009, 11:55 PM
You're completely right about that, and I do actually use three-way switches for all such contraptions. Still, I'm really curious if anyone found an actual use for the built-in hysteresis...

I've got one. A slightly lower thermo version of my dissolve free p-switch. You tweak it so that the starting point of the mag key is in the hystersis zone, then you activate the piston. At this point the key acticates, but it can never deactivate, because it will never move OUT of the hysteresis zone. TBH though, that's contrived and I don't trust the reliability of it.

Realistically, hysteresis is great for rounding errros / fluctuations and such. You will never notice these things, but hysteresis isn't there to be noticed, or to add explicit features - it's one of those things you notice because of its absence. You don't notice the hysteresis in your thermostat, but you would notice it not being there when your boiler breaks, for instance :p

srgt_poptart
10-20-2009, 01:27 AM
I suppose so. It's one of the things we take for granted in LBP.

lbpholic
10-22-2009, 07:52 AM
awesome I am in the process of making a music level using mag keys but some don't play because of the circular area of the activation area as it where this really helped thanks a lot!