Controlling two ends of a bar separately

For questions about using Classic.

Post » Tue Dec 01, 2009 9:18 am

So here's my dilemma. I'm making a game that involves controlling a bar. One set of keys, WASD I guess, will move one end of the stick. The other set, arrow keys or numpad, will control the other. The goal is so that I am controlling a bar, like a stiff iron rod, where I control the movement the two ends separately.

That might be hard to picture so here's an example.

[L]------[R] <-- bar, with two ends.

If I press W, that makes the left side of the bar go up. So then it should look something like this

. . . . [L]
. . . . .|
. . . . .|
. . . . [R]

And after that, if I press left arrow and down arrow, the right side moves in that direction. Like this

. . . [L]
. . ./
. ./
[R]


Problem number one is getting the line to stay rigid. If I used a Line object, then it'll stretch and stuff and I have no idea how I could get it to stay a certain length and still be able to control it the way I want. Problem number two is that the bar rotates on each end the right way. So if I only move one end, the other end stays still, like it's just moving in a circle. I only want the bar to move completely if I move both ends at the same time. This also means that if I do complex motions like, move the left end upwards and the right end to the side, it still works right.

You can get an idea of what I'm doing by putting a line between two sprites with 8Direction movement and just, move them. The only thing I want different is for the two sprites to always be the same distance from eachother.

So if anyone has any ideas to help me with this, I'd greatly appreciate it.
B
3
G
3
Posts: 12
Reputation: 1,224

Post » Tue Dec 01, 2009 12:24 pm

Why don't you just use the rotation behavior on a sprite? That's all your doing isn't it, rotating it one direction or the other?
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Dec 01, 2009 1:54 pm

[quote="newt":13u6cudk]Why don't you just use the rotation behavior on a sprite? That's all your doing isn't it, rotating it one direction or the other?[/quote:13u6cudk]

Not exactly, because that would make it rotate at the center, so it would have both ends moving at the same time. I need both ends of the stick to be in control.

Imagine playing this with a Playstation controller. You have two analog sticks. One analog stick controls the left end of the stick, and the other controls the right. If I move the left stick in a direction, the left end of the stick goes that direction, but the other end of the stick has to stay still.

It's not like - / | \ - kind of movement. It's more like _\|/_. If that helps at all.

Maybe another visual example. Look at this game http://www.youtube.com/watch?v=A3cT_DJQj1I

He's controlling two boats with a line in between, the only difference between that and the thing I need is the line between needs to be the same length at all times. So the two 'boats' are at the same distance away from eachother all the time. (cool game btw)

If you want a physical example, take a staff or something and hold both ends. And just move it with one hand at a time. Move your left hand up, but your right hand still. And then the other way around. I don't know a better way to explain it than that.
B
3
G
3
Posts: 12
Reputation: 1,224

Post » Tue Dec 01, 2009 2:54 pm

[quote="Evil_Toaster":2lq6qx2h][quote="newt":2lq6qx2h]Why don't you just use the rotation behavior on a sprite? That's all your doing isn't it, rotating it one direction or the other?[/quote:2lq6qx2h]

Not exactly, because that would make it rotate at the center, so it would have both ends moving at the same time. I need both ends of the stick to be in control.

Imagine playing this with a Playstation controller. You have two analog sticks. One analog stick controls the left end of the stick, and the other controls the right. If I move the left stick in a direction, the left end of the stick goes that direction, but the other end of the stick has to stay still.

It's not like - / | \ - kind of movement. It's more like _\|/_. If that helps at all.

Maybe another visual example. Look at this game http://www.youtube.com/watch?v=A3cT_DJQj1I

He's controlling two boats with a line in between, the only difference between that and the thing I need is the line between needs to be the same length at all times. So the two 'boats' are at the same distance away from eachother all the time. (cool game btw)

If you want a physical example, take a staff or something and hold both ends. And just move it with one hand at a time. Move your left hand up, but your right hand still. And then the other way around. I don't know a better way to explain it than that.[/quote:2lq6qx2h]

Well I can't help with how to do it, only that I'm pretty sure it's possible using events. Say for example you use the xbox controller object. That gives access to all the buttons/directions. So then if you were to use events to control what moves what and where, rather than properties, it'll solve the problem with controlling things independently.

Then I think it's simply a case of setting up an event which checks the distance between the two ends of the pole and preventing them from moving further apart or getting closer together. Which should be doable. As for changing the pivot point, erm.. maybe some event that if X moves, then play pivot on Y's position, and viceversa, could that work? Hmm, it's difficult to explain isn't it? lol. I DO know what you're after, I just can't word it right. :)
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Tue Dec 01, 2009 3:59 pm

There's an expression distance(x,1,y1,x2,y2) you can use that to check or set the distance between two points.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Dec 01, 2009 5:52 pm

First I thought I would be able to do this with the Orbiter plugin, but as it turns out that one doesn't like setups where two objects orbit each other, so to speak. :P

Anyway, my first tries at achieving something new are usually pretty bad, but I came up with the following:

[url:1ly1wre7]http://dl.dropbox.com/u/2306601/sticky_002x6.cap[/url:1ly1wre7]

If I understood correctly what you wanted to achieve, this should at least come somewhere close.
A and D rotate around one end of the stick and left and right arrows around the other. I don't know really how this should act, but rotating both ends at the same time in opposite directions results in the whole thing moving. You could also block this kind of behavior if it isn't wanted...

Ah well, just tell me if this was useful. :?
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Tue Dec 01, 2009 7:47 pm

yeah I agree you probably want a rotating sprite, as this will keep it the same size.

What I believe is what you do NOT want is to control rotations directly. So, put some work on how the controls translate to rotations. Math will be involved. Cosines will be touched. It won't be pretty.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Dec 01, 2009 9:45 pm

you can "set pivot point" by events maybe that can help
B
2
G
3
Posts: 72
Reputation: 994

Post » Tue Dec 01, 2009 10:53 pm

[quote="PixelRebirth":2b7nufv4]First I thought I would be able to do this with the Orbiter plugin, but as it turns out that one doesn't like setups where two objects orbit each other, so to speak. :P

Anyway, my first tries at achieving something new are usually pretty bad, but I came up with the following:

[url:2b7nufv4]http://dl.dropbox.com/u/2306601/sticky_002x6.cap[/url:2b7nufv4]

If I understood correctly what you wanted to achieve, this should at least come somewhere close.
A and D rotate around one end of the stick and left and right arrows around the other. I don't know really how this should act, but rotating both ends at the same time in opposite directions results in the whole thing moving. You could also block this kind of behavior if it isn't wanted...

Ah well, just tell me if this was useful. :?[/quote:2b7nufv4]

This is very useful. It's almost exactly what I'm looking for. I'm gonna study it and mess around with it to see if I can get exactly what I need.

Something I didn't explain well before was that I also want the bar to move in any one direction if both ends are moving that way. So if I held W and Up arrow than the bar would move up no matter what orientation it was. Then there's more complicated things like if I held W and Right arrow, then it should move up but one end move right. Or something along those lines. I'm not quite sure how the more advanced movements will control. I just need it two control in a way that makes sense.

But for right now, I'll work with this cap. It's very helpful. I'll sort out all the controls and stuff later and check back if I run into any road blocks.

But if anyone else has anything insightful, don't hesitate to let me know. :wink:
B
3
G
3
Posts: 12
Reputation: 1,224

Post » Thu Dec 03, 2009 9:44 am

I think I figured out a couple of ways to do this with much less scarier event sheets.

http://dl.dropbox.com/u/3314752/bar.cap

I control the ends of the bar with 8Direction and and fix the distance between the two with CustomMovement. For the most part, it works just fine. The only problem I really have is when both ends move at the same time. Because of the way the code is ordered, if I make the ends go in opposite directions, it doesn't stay still. I'm still thinking of a few ways to fix it, or different ways to do this entirely. At the end of the day, it has to be done in a way that's easy to control and makes sense, so I can make intricate movements with the bar with just two sets of keys or two analog sticks. And I think what I got is on the right track.
B
3
G
3
Posts: 12
Reputation: 1,224

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests