PDA

View Full Version : How to limit an object's movement to a bounding box, smoothly



Antikris
05-06-2011, 09:25 PM
http://i.imgur.com/m3THu.jpg

Hiya. I am Kris and today I am going to let you in on a simple technique to keep a moving, controlled object from going outside an invisible bounding box.

There are techniques out there that give mixed results. You may have tried a few yourself, varying from using followers that make the object flee from the sides to removing user control and bouncing the object back into the arena. No such thing here, though. I set out to make this one work as smoothly as possible; as if you are pushing up against an invisible wall and without losing control of your object.

http://i.imgur.com/rpEaJ.jpg

Start off with something like this: a block of holographic material with a controlinator on it; as you can see here, the left/right and top/down output of the left joystick are hooked to an advanced mover (don't forget to set its deceleration to 100%. Thanks Deafmanwalking (http://www.lbpcentral.com/forums/showthread.php?56251-How-to-limit-an-object-s-movement-to-a-bounding-box-smoothly&p=857289&viewfull=1#post857289)). If you'd hop into the controlinator right now, you can freely move block around. We want to go and limit that to an invisible bounding box.

Whatever movement you make with the joystick, it can always be split up into a horizontal vector and a vertical vector. For example, you move the block into a north-west diagonal direction; this means there is a negative movement on the X-axis combined with a positive movement on the Y-axis. We are going to use this principle.

http://i.imgur.com/eUs2v.jpg

Here I have split up both the horizontal signal and the vertical signal from the joystick, using signal splitters. I hooked each separated signal to its corresponding input of signal combiners to put them back into a composite signal again and feed those into the advanced mover. Why? Good that you ask. We'll be using those splitted signals soon.

http://i.imgur.com/vXvcq.jpg

Let's focus on the bounding box now. We'll be needing not just one rectangular shape, but four separate pieces in order to distinguish between the upper, lower, left and right boundary. Make them from holographic material set to 0% brightness so that they will be invisible in play or preview mode. Tag each side of our boundary with a unique tag. For instance "North", "East", "South" and "West". Glue everything together so you can easily move the box later if you need to.

http://i.imgur.com/l05jQ.jpg

Now here is where we put it all together! In between the signal splitters and signal combiners, put an AND gate for each separate signal. So, four total. Hook their output to the signal combiners like in the picture. Also, connect the signals from the splitters to the inputs of the AND gates, just like displayed above.

What we need now is to accompany each of the splitted signals with an impact sensor. One for tag "North" paired with the positive (+) part of the vertical signal. One for tag "South" for the negative part (-) of the vertical signal. "East" goes with the (+) of the horizontal signal and "West" with the (-) of the horizontal signal. Set all the impact sensors to accept touching, but not rigid connections. Also set them to output a reverse signal; this means that they will give off a signal when the moving object is NOT touching the boundary.

Connect each impact sensor's output to an input of the AND gate.

Putting it to the test

What will happen when you jump into the controlinator is that you can now move freely around until you hit a boundary. For instance, you hit "North": the impact sensor for "North" will register and stop giving off a signal, meaning the AND gate with the (+) for vertical movement will be interrupted and there will no longer be any "up" movement put through into the vertical signal combiner. The block will stop moving up. However, all the other signals will be uninterrupted. This means, you can move the block down, sideways, or whatever you like.

No bouncing, no friction, no loss of control. Smoothly!

Jayhawk_er
05-06-2011, 09:30 PM
Wow, the funny thing is I've seen this so many times but I could never really figure out how it worked haha It could just be my ignorance to all things logic, but anyways... thanks! :)

evret
05-07-2011, 01:12 AM
the issue with this setup is the fact you lose analog control over the mover, for example you cant hold the stick half way to move half speed, to fix this you need to remove the AND gates from the setup.
in your second picture, put a node in the middle of each of the 4 wires, so each wire goes through it's own node, then move each node into it's own microchip, then connect the inverted impact sensors to the corresponding microchips. this will still behave the same with the bounding box, but you will have full analog control

ShadowTyphoon
05-07-2011, 01:15 AM
good point evret, ive used that technique b4 as well

You dont need any of this logic if you use holograms with collision.

heres the thread i posted for it
http://www.lbpcentral.com/forums/showthread.php?56150-How-to-create-glitched-holograms....&p=840784#post840784

You can add a material tweaker to the holograms, set physics sounds to none, 0 friction and a rocket rotator to keep it straight. Making the hologram your on a circle will help.

not sure if this would be smoother but wil def save u some logic space. Of course your technique will be more usefull in certain circumstances so thx for the tip.

evret
05-07-2011, 01:28 AM
the problem with that is you cant use the layer you use for the cursor and bounding box to build your level, using this logic method is still rather simple but allows you to use all layers as normal for your level.
there is also a glitch that makes neon material invisable, it has slightly different uses to the glitched holo because sackboy collides with it too, not just materials. not sure how to recreate it coz PPp_Killer just gave it to me in create mode and i just corner edit it to the shape i want when i need it

ShadowTyphoon
05-07-2011, 01:32 AM
You could create the collisionss to occur in the foreground, and have them stem with normal hologram into the normal dimensions, but i could see how that could end up being a hassle.

Antikris
05-07-2011, 09:45 AM
the issue with this setup is the fact you lose analog control over the mover, for example you cant hold the stick half way to move half speed, to fix this you need to remove the AND gates from the setup.

That was my concern with this setup as well, but I am using this exact setup in a level of mine and the problem you describe does not occur; I can move at variable speeds and the impact sensor is not overriding that with its 100% signal strength. This may be something I don't understand; perhaps when it comes to AND gates the lowest of values gets passed through. I know that OR gates behave similarly in that they pass through the strongest of incoming signals...


You dont need any of this logic if you use holograms with collision. heres the thread i posted for it
http://www.lbpcentral.com/forums/showthread.php?56150-How-to-create-glitched-holograms....&p=840784#post840784
You can add a material tweaker to the holograms, set physics sounds to none, 0 friction and a rocket rotator to keep it straight. Making the hologram your on a circle will help.
not sure if this would be smoother but wil def save u some logic space. Of course your technique will be more usefull in certain circumstances so thx for the tip.

Going physical to save a few bits of logic would be the opposite of a good idea to me. Sooner or later it will dictate what you can and cannot do in your level, so I like to keep my options open. For instance, if the holo barrier in my example would be physical, I would not be able to make enemies, bullets and other objects to move through it, unless I reserve one plain in the entire level for that bounding box (which in turn only limits one object).

An example is the camel shooter level in Story Mode, where you control a cursor from the back of a vehicle; the cursor's movement is bound to an invisible box that moves along with the vehicle.

evret
05-07-2011, 11:02 AM
i just did a few tests and yeah your right, AND gates will output the value of the lowest input, aslong as all inputs have some form of active input. i assumed they outputed the highest value like OR gates but had never tested it till now. definitely good to know

Broonba
05-07-2011, 06:31 PM
Am i right in thinking that this technique could be used to keep my Landspeeder off the ground ?? ........Using just the N & S Holos placed @ top & bottom of the Landspeeder (set to follow a tag on the speeder)

Antikris
05-07-2011, 07:29 PM
Am i right in thinking that this technique could be used to keep my Landspeeder off the ground ?? ........Using just the N & S Holos placed @ top & bottom of the Landspeeder (set to follow a tag on the speeder)

I think you can, yes.

Bremnen
05-07-2011, 11:52 PM
If you're just trying to keep an object inside of an holo box, you can use a rope and set it to invisible.

Broonba
05-08-2011, 03:58 PM
I think you can, yes.

Thanks for the reply man........I tried it out (using the N & S method & it works perfectly :)
I put them so that they were both touching the speeder........It now has full L/R movement & no U/D, so it now "appears" to levitate above the ground.
Thanks again for the idea.

DeafManWalking
05-26-2011, 11:19 AM
Just one thing worth knowing to beginners like me:
For this to work you need to set Deceleration to 100% or similar in the Advanced Mover. Otherwise keeps moving through the holo.

ScorpSkull
05-28-2011, 09:35 PM
I also did a tutorial about this.

Check it out if you want to see how to create it ;)


http://www.youtube.com/watch?v=2TcyNkqxMAA&feature=channel_video_title

SSTAGG1
06-06-2011, 11:07 PM
If anyone finds an effective way to produce this for a moving screen, please tell. My creations with this all rely on the cursor to bounce back off the walls, otherwise you could simply just leave the cursor behind as you move away.

Using a physical means like a string to restrict movement works for this, but an completely logic based method would be nice.

Antikris
06-07-2011, 06:03 AM
If anyone finds an effective way to produce this for a moving screen, please tell. My creations with this all rely on the cursor to bounce back off the walls, otherwise you could simply just leave the cursor behind as you move away.

I made bouncing behavior before as well and it left me really unsatisfied, hence the focus on "smooth" in the title of my post. :)

The blocks that making the bounding box in my tutorial can be glued together and moved. You can either move them by logic or glue them to another base object that moves - like the camel in the Story Mode shooter level.



I also did a tutorial about this.

Great video! Keep on sharing.

SSTAGG1
06-07-2011, 06:28 AM
I made bouncing behavior before as well and it left me really unsatisfied, hence the focus on "smooth" in the title of my post. :)

The blocks that making the bounding box in my tutorial can be glued together and moved. You can either move them by logic or glue them to another base object that moves - like the camel in the Story Mode shooter level.
I meant just for a moving box I had the bouncing. I've produced several of the border versions myself (my level menu test even has it).

My question is how exactly would you get the cursor to move in step with the moving frame. It can be done for views that move at constant speed, but ineffective for variable AFAIK.

Rogar
06-08-2011, 02:20 PM
My question is how exactly would you get the cursor to move in step with the moving frame. It can be done for views that move at constant speed, but ineffective for variable AFAIK.

The frame could transmit the current speed through a tag (one for up-down speed, one for left-right), the cursor can pick it up and split the positive (right) or negative (left) component of the speed tag sensor signal. In stead of turning off the movement when colliding, you set the speed to the speed of the frame with a microchip as a relay.

For example, when the frame moves right, the frame sends speed 3 through the Left-Right tag. If you hit the left border, you want to use the positive component of that tag (3) to move right, and if you hit the right border you want the negative component of the tag (-0).

Actually, that's not quite right either. If you hit the left border, you want to use the Left-Right tag speed if the player's speed is less, and if you hit the right border you want to use the Left-Right if the player's speed is greater. Yeah, that sounds about right. Helps thinking backwards.

So uhm, you can take it from here? :)

L78948
07-11-2011, 12:29 PM
Hmmmm I followed all the instructions but its still going through it.... obviously I have done something wrong :/

Mr_Fusion
07-12-2011, 07:23 AM
If anyone finds an effective way to produce this for a moving screen, please tell. My creations with this all rely on the cursor to bounce back off the walls, otherwise you could simply just leave the cursor behind as you move away.

Using a physical means like a string to restrict movement works for this, but an completely logic based method would be nice.

I was checking out something that Evret was messing with in his create mode, the rig was... Impressive to say the least.

He actually had to explain what it did... couldn't really understand HOW it did it.

The cursor can be moved with R Stick and stays in the 'same' spot relative to sackboy, and is limited to how far away it can go.

Still digesting how it works, but it's not up to me to share it, he didn't say top secret, but I don't think its 100% ready.

But, It did inspire me to have a crack at it... well sort of.

In the (scrapped) 2 player version of my stage Miserable Flying Weather, I actually use something to this .

Player 2 can zoom around a screen on a hover board but needed to grab a rope on the DeLorean controlled by player 1. When grabbing a rope attached to Player 1, they lost all control until they let go. Their position stayed the same distance from P1 and if P1 moved they moved with them.

I'll see if I can re-purpose it to be a cursor. In it's current build I'm pretty sure it'll work, but the only thing it won't do is respond to pressing jump. It also relies on using a sackbot.

If I get it working; I'll give it a stupid name and share it.


Hmmmm I followed all the instructions but its still going through it.... obviously I have done something wrong :/
Jump onto scorpskull's (http://www.youtube.com/watch?v=2TcyNkqxMAA&feature=player_embedded) video next and grab (http://lbp.me/v/2m4w83) my example to play with.

SSTAGG1
07-12-2011, 12:21 PM
I was checking out something that Evret was messing with in his create mode, the rig was... Impressive to say the least.

He actually had to explain what it did... couldn't really understand HOW it did it.

The cursor can be moved with R Stick and stays in the 'same' spot relative to sackboy, and is limited to how far away it can go.

Still digesting how it works, but it's not up to me to share it, he didn't say top secret, but I don't think its 100% ready.

But, It did inspire me to have a crack at it... well sort of.

In the (scrapped) 2 player version of my stage Miserable Flying Weather, I actually use something to this .

Player 2 can zoom around a screen on a hover board but needed to grab a rope on the DeLorean controlled by player 1. When grabbing a rope attached to Player 1, they lost all control until they let go. Their position stayed the same distance from P1 and if P1 moved they moved with them.

I'll see if I can re-purpose it to be a cursor. In it's current build I'm pretty sure it'll work, but the only thing it won't do is respond to pressing jump. It also relies on using a sackbot.

If I get it working; I'll give it a stupid name and share it.


Jump onto scorpskull's (http://www.youtube.com/watch?v=2TcyNkqxMAA&feature=player_embedded) video next and grab (http://lbp.me/v/2m4w83) my example to play with.
LOOOOOOOL. Seriously, lol. Yesterday, I was going to make a post explaining this exact thing, based on evret's positional movement design and everything! I thought I'd go ahead and make it look nice before I posted it, but wow, what a coincidence.

Have you made a nice design for it. All that needs to be done is set up the location based on distance from each tag. This would be done in a stationary box, the same size as the one that will be moving. The cursor in the moving screen would then change position in relation to where you move the cursor in the stationary screen.

It 'should' work perfectly, at least for what I would need it for.

I should also point out that the string setup is probably the best option. By just attaching a string to the center of the screen and the cursor/etc, you make very effective limiting system for how simple it is. I use this for my Mercenaries game (although that's really only relevant to whoever has seen it :p).

evret
07-12-2011, 03:04 PM
lol, yeah i used a modified (again :P) version of the positioning system to make the cursor move relative to a sackbot, got all the kinks worked out too (after a lot of cussing)
it would be easy to make it move relative to a screen or any other object too.

pivottt
07-12-2011, 05:30 PM
I didn't get all what you guys are talking about, but good luck with your logic.
For your knowledge, AND takes the lowest signal, OR takes the biggest. NOT makes 100% minus signal, so a NAND would take 100 - lowest and NOR 100 - biggest. I'm not sure about how to use XOR and XNOR, but in english speaking, XOR : if and only if one is on /// XNOR : all or nothing.

With some logic and AND gates or OR gates (lol) you can test which signal is the biggest. That's how I made my thank :
Use a piece of logic that outputs the 1st output 100% if Left-right is "bigger" than Up-down. Note the use of " " around bigger, because -2 is bigger than 1 in this system. "Most far from 0" is the correct name for my logic. It outputs from the 2nd output if U-D is bigger than L-R. I place a node on a chip and make the L-R signal go through it before reaching the logic made just like the one in the first post. I do the same with the U-D. With this, if I press more up (or down) than I press left (or right), I will go up (or down) and so on. In english, it means I deleted diagonal movement, but it is still analog!

Mr_Fusion
07-12-2011, 08:53 PM
got all the kinks worked out too (after a lot of cussing)

Not to mention me distracting you, like I knew how to help. Also, no offence to your system but it looked sooooo LBP1 :D

But I can't really talk... I'm still trying to rebuild that staircase thingy you showed me so I can begin to understand the madness!

I should stress to Evret that what I have is very different to you and I'm not trying to reverse engineer your efforts. When you showed me your rig I just started wondering if I had somehow stumbled on to a solution when making something for an entirely different purpose.

Last night I pulled apart what I already mentioned and repurposed it and it looks so much cooler than Evret's. It doesn't work. But it looks great.

Well, it kind of works. It works for a flying DeLorean, and a variable moving screen but doesn't work all that well when a sackboy is introduced as the point to follow!

Mr_Fusion
07-14-2011, 11:41 AM
So I have the first version on the Mr. Cursorator up and running.

Staying away from sackbots and the like it works well. I could see it being quiet useful for an RTS or similar top down game and it is essentially two cursors overlaid. One controls the camera zone (with bounding box edges) the other controls the select cursor.

The select cursor moves independently, but also in step with the view. It works and it works well...

The next part of it is to have it respond to the edge of the screen. So if you push the cursor to the edge of the screen and keep pushing it will scroll the screen. This bit does sort of work but at the moment the cursor judders when it transitions to camera control.

EDIT: As I type this I realise that after an hour of playing, this may be a little silly in terms of logic. If you want the cursor to do this you could just make a floating cursor that has camera tracking and do away with the bounding box all together... so not sure if it is useful to have scrolling after a pause... thoughts?

Also without tipping my hand too much I think that I have a half hatched scheme to make a select box that you can click and drag... but it requires a better understanding of positional movers that lock to only one axis.

Antikris
07-14-2011, 05:46 PM
EDIT: As I type this I realise that after an hour of playing, this may be a little silly in terms of logic. If you want the cursor to do this you could just make a floating cursor that has camera tracking and do away with the bounding box all together... so not sure if it is useful to have scrolling after a pause... thoughts?

It is actually very useful to stop the scrolling. Especially in an RTS things can become very hectic and having the screen move with the cursor at all times is not a good thing, IMO.


Also without tipping my hand too much I think that I have a half hatched scheme to make a select box that you can click and drag... but it requires a better understanding of positional movers that lock to only one axis.

Not sure if you already can, but try and see if you can include Move support when it comes out. Keep it flexible. :)

evret
07-15-2011, 03:38 AM
Not to mention me distracting you, like I knew how to help. Also, no offence to your system but it looked sooooo LBP1 :D

it only looks lbp1 while in create mode, in play or preview all you see is the cursor and sack bot.
the only issue with using positional movers is it can cause massive visual issues with online lag



Also without tipping my hand too much I think that I have a half hatched scheme to make a select box that you can click and drag... but it requires a better understanding of positional movers that lock to only one axis.

i've seen a very good drag select box done b4, however i cant really talk about it in this forum :P
it can b done in retail though coz it doesnt need any tools i cant talk about......lol

SSTAGG1
07-15-2011, 03:48 AM
the only issue with using positional movers is it can cause massive visual issues with online lag
Lol, it sure does. That was likely due to being on opposite sides of the world though.

Also, bah, keep your secrets :p.

Mr_Fusion
07-15-2011, 07:13 AM
@Evret

It was funny seeing something so advanced using string and pistons.

It really highlighted to me that my default to use holo and follower logic may not always be the best place to start when creating logic, LBP 1 tools are still valid.

And if you are suggesting that I shouldn't move on making a select box the maybe I should just polish off what I have and share it. To be honest it's not that amazing. I thought that somebody would have already made this setup. So I just need to make sure that mine is cooler but has a stupider name.

evret
07-15-2011, 04:33 PM
nah there's nothing wrong with making your own, i know how to do one myself (i didn't see how the other was done) but i just havnt had the need, nor had a request for one so i havnt bothered

TheGoldenFlash
07-23-2011, 02:33 PM
Yeah that was very necessary for my upcoming level. Thanks!

Mr_Fusion
07-24-2011, 02:39 AM
I updated my logic stage (http://www.lbpcentral.com/forums/showthread.php?59299-Doc-s-Workshop-RTS-Cursor-Molvement&p=894048#post894048) to show a simple application of cursor movement. It's pretty basic but the concept is what people want to see and maybe build on. I have seen better versions that follow a Sackperson, but here is what I made a while back to help in my stage.

http://i5.lbp.me/img/ft/3b5d810162fae701a641ad0e8aeae39570e3bc26.jpg

It's a basic interruptor circuit that will move the cursor with the Right Stick, if you input on the Left Stick, the bounding box will move, and it will move the cursor at the same speed also. Simple. If you are moving the screen (the bounding box) it turns of control of the cursor input. It works in principal and could see it work in an RTS.

I really though that people would already have made this, so yeah. I didn't do much to it, just pulled it out of the stage I built it for and made it shareable.

SSTAGG1
07-24-2011, 03:50 AM
Current bounding box design I use is 2 strings attached to either side of a the holo cursor (other ends attached to the central system). Works perfectly, is incredibly simple, and very easy to adjust. Only drawback is it forces a circular box (which imo, is a good thing). You could adjust the shape of the box by just using more strings positioned properly. If you do this, be sure to set strength to ~90%, so that the mover doesn't pull the central mass around.

Nurolight
07-24-2011, 10:36 PM
In my Zombie level, I made a different technique;
Draw the boundry box (all walls) in holo, then Tag. Place a Holo point in the centre, and tag that. Now, simply place a Touching-Impact sensor, that connects to a follower, that wants to go to the centre Tag. Just make sure its more than double the normal movement speed, and its set!

SSTAGG1
07-24-2011, 11:36 PM
^^ Thing about that though is that it'll bounce when you get to the edge, which is what we're trying to avoid.

Yeah, yeah, shameless plug, but my merc demo uses the 2 string design if anyone is interested in seeing it. 1 string isn't as stable (the holo could spin even with a gyro, makes it wobble oddly)

tdarb
08-02-2011, 05:06 PM
very cool. Nice writeup. I did a similar version of that to work with grids.

I have a pic if you would like to see.

julesyjules
07-19-2012, 10:20 AM
Just one thing worth knowing to beginners like me:
For this to work you need to set Deceleration to 100% or similar in the Advanced Mover. Otherwise keeps moving through the holo.

Yep, the OP set up works great, butI wasn't keen on the 'on rails' feel that no deceleration has. Just add an additional mover with the deceleration and set it up so it reverts once you're away from the boundaries.