Page 1 of 1

Pushing the Limits :: Scripting Straight Line Movement

Posted: Thu Dec 06, 2007 9:19 pm
by Redsatori
In this issue of Pushing the Limits, we will be discussing how to make parts move in a straight line. We will be discussing three different types of straight line movement. Two of them are not "true" straight line motions, but rather small arcs on a large circle. Some of this will be technical, especially if I decide to throw around my hyperbolic movement in addition to the others. I will be doing my best to make this as easy and painless as possible.

One thing you should be aware of, however, is that each of these types of motion have their advantages and disadvantages. They all have a different use, and should be applied as you see fit in your levels. Remember, in the end only you, as the designer, know for sure what you want your level to look like.

Straight Line Movement, Part 1

Our first type of straight line movement is by far the easiest to implement. You can find the link for the level here. I will be referencing the circular parts from left to right, starting with 1. The scripting for this is quite easy as well.

Code: Select all

rotatePart, 1, 1, 0, 0, 0
rotatePart, 2, -2, 0, 0, 0
rotatePart, 3, 1, 0, 0, 0
What we have done here, is told part #1 to rotate clockwise indefinitely, told part #2 to rotate counterclockwise and twice the speed of part #1, and told part #3 to rotate clockwise at the same speed as #1. The first thing this does is zero out the rotation of part #3. It stays at the same orientation at all times. This is not absolutely a requirement. You could, for instance, change the code to look like the following.

Code: Select all

rotatePart, 1, 1, 0, 0, 0
rotatePart, 2, -2, 0, 0, 0
rotatePartToShip, 3
This would have the third piece moving in a straight line, while at the same time having it aim always towards the player's ship. Some interesting effects can be done with this. It allows you to force the player to move their ship to keep fire on this piece, or make them stay in one spot waiting for the return. Either way, with other elements added to your level, this can prove to be quite difficult to overcome.

One thing this type of straight line motion will do, however, is that near the endpoints of the line, the part will slow down. This can either be a hindrance to your level's overall effect or it can add to it. You decide if it's right for you.

Straight Line Motion, Part the Second

If part limits are imposed (see: Minimalist thread), or you'd like to reduce lag a bit, this second option might just be the ticket you are looking for. This technique only uses one rotating part, making it especially useful for levels with many parts and/or weapons or a lot of scripting. The major downside to this techinque is that the arc that you use, is generally clearly visible. That is unless you move your parts way off the screen. (I will detail a bit more on how to move your parts off the screen in just a moment.) You can view this type of straight line motion here.

I will be using the piece at the top as the rotator in this example. It will be called part #1 in all code fragments. The code I used for this is also as simple as the rotator itself.

Code: Select all

rotatePart, 1, 0.25, -10, 10, 0
As you can see, we are really just moving the part through a small portion of the circle that would be normally made on this rotation. The radius in this case is 500 pixels, and we are moving between -10 degrees and 10 degrees, albeit very slowly (0.25.) Now, there is a way to place this completely off the screen, especially if you would like to make it a bit more of a straight line. If you were to adjust your browser's size, you would be able to scroll around more of the playing field, including the negative number section and quite high in the upper ranges. By changing your browser to say, very thin vertically, you would be able to see quite a bit to the left and right of the playing field. This is because, even when your browser is resized, Flash Player attempts to keep the same ratio for the game itself. If you'd like more information on this, there is a post in the Help section of the forums written by MD that discusses it in more detail.

The main advantage of this type of straight line movement is that you can use fewer parts to make things move. The biggest disadvantage is that it is really only a small portion of a circle's arc. This causes the part to move in a circular fashion, even if only slightly. This can cause problems if you need things to line up in a Cartesian world, although not so much if everything is spinning around anyways. One other disadvantage is that if you place the rotator outside of the playing field, you have to be careful when moving and rotating the core that you keep it out of sight at all times.

Straight Lines: Three Time's a Charm

So there was giong to be a third segment to this article, but I can't seem to make any sense of the trig I compiled to figure what it actually means anymore tonite. I did, however, know exactly how it worked when I wrote it down. Sometimes I hate getting old. If I figure it out, I will post it here.

Please discuss anything about this post here. Share some things that worked for you, or ideas you might have on making this actually work a bit better. And if you have an idea for the next episode of Pushing the Limits, let me know. I'd be happy to figure it out.

Posted: Fri Dec 07, 2007 2:12 am
by Mouzi
It is also possible to do the horizontal movement without slowdown in the ends.

See here.

Here are the modifications:

Code: Select all

rotatePart,1,5,45,135,45
rotatePart,2,-10,-270,-90,-90
rotatePart,3,5,45,135,45
There is still going to be some unnoticeable slowdown, but I don't think it matters :P
Or did you notice? I doubt.

Posted: Wed Jan 16, 2008 9:38 pm
by Sethum
Thank you for this excellent tutorial!

Only now, I'm stuck at the next step in reworking constant rotation into sinusoidal motion: sinusoidal rotation. Basically, I'd like to simulate the motion that a fixed camera would go through if it was focussed on the linear motion block you've made above. The "camera" would always be pointed at the linear motion block, so it would repeatedly rotate back and forth over a finite arc, but it's rotation would also slow down and speed up based on the speed of the linear motion block (sinusoidal). Is that even possible to achieve with only constant-speed rotations? I've been playing around with series of connected rotators, but I can't get anywhere near the right motion. Any help?

Posted: Tue May 20, 2008 11:48 am
by Sasadad
This is great! I've been using this technique since I first read this thread, and it has been very helpful. :)