Controlling two ends of a bar separately

This forum is currently in read-only mode.
  • 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.

  • 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?

  • 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?

    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

    Subscribe to Construct videos now

    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.

  • > 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?

    >

    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

    Subscribe to Construct videos now

    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.

    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.

  • There's an expression distance(x,1,y1,x2,y2) you can use that to check or set the distance between two points.

  • 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.

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

    http://dl.dropbox.com/u/2306601/sticky_002x6.cap

    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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • you can "set pivot point" by events maybe that can help

  • 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.

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

    http://dl.dropbox.com/u/2306601/sticky_002x6.cap

    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.

    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.

  • 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.

  • Very cool solution. Custom Movement, why do I never think of that?

    Regarding your problem: if they should stand still when moving in opposite directions, you could compare the movement angles of the 8 direction movements of both sprites. If it's equal to 180 you set both speeds to 0. Could look like that:

    <img src="http://dl.dropbox.com/u/2306601/opposite.png">

    So that's a system compare. If you care to test it yourself just copy this to compare to 180:

    round(Anglediff(Sprite[8Direction].movangle,Sprite2[8Direction].movangle))[/code:1cqpjewz]
  • Very cool solution. Custom Movement, why do I never think of that?

    Regarding your problem: if they should stand still when moving in opposite directions, you could compare the movement angles of the 8 direction movements of both sprites. If it's equal to 180 you set both speeds to 0. Could look like that:

    <img src="http://dl.dropbox.com/u/2306601/opposite.png">

    So that's a system compare. If you care to test it yourself just copy this to compare to 180:

    round(Anglediff(Sprite[8Direction].movangle,Sprite2[8Direction].movangle))[/code:1v0uryvq]
    

    Close, but the problem with that is that it will stop the ends from moving even the bar is not being pushed in the right two directions.

    Uhh, for example. If the bar is like this

    [L] <--

    |

    |

    |

    [R] -->

    And I make the left end go left and the right end go right, as shown with arrows, it won't move.

    The end goal is to have it so each of these ends that I pulling with the 8Direction sprites act as if they were pulling the bar physically. So if I pulled it in one direction with one sprite and the opposite direction with the other, they would align in those two directions. You know, as if you were really pulling two ends of a stick. The two 8Direction sprites are forces on the bar between them. At least, that's how I'm trying to make it.

  • Close, but the problem with that is that it will stop the ends from moving even the bar is not being pushed in the right two directions.

    Yeah, so add some conditions that check for the angle of the line as well?!? I'm pretty sure it's not the most elegant solution, but here's an example which seems to work for me:

    bar3.cap

  • I've finally came up with the solution.

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

    Works perfectly and realistically.

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