Controlling two ends of a bar separately

» 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

» Thu Dec 03, 2009 11:27 am

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:

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

[code:1cqpjewz]round(Anglediff(Sprite[8Direction].movangle,Sprite2[8Direction].movangle))[/code:1cqpjewz]
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

» Fri Dec 04, 2009 1:56 am

[quote="PixelRebirth":1v0uryvq]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:

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

[code:1v0uryvq]round(Anglediff(Sprite[8Direction].movangle,Sprite2[8Direction].movangle))[/code:1v0uryvq][/quote: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.
B
3
G
3
Posts: 12
Reputation: 1,224

» Fri Dec 04, 2009 2:44 am

[quote="Evil_Toaster":2n11e0ow]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.[/quote:2n11e0ow]

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
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

» Wed Dec 09, 2009 10:45 pm

I've finally came up with the solution.

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

Works perfectly and realistically.
B
3
G
3
Posts: 12
Reputation: 1,224

Previous