Hey folks... I want to do a number of very special scripting things with some of the units I'm working on, and I'd really like some help figuring out how.
1. I'd like to be able to determine if a unit is turning right (clockwise) or left (counterclockwise). This would be a script that every quarter-second (or so) would return a value of either 0 ("I'm not turning fast enough to bother with"), 1 ("I'm turning right"), or 2 ("I'm turning left").
Sooo, how do I write something like this? I had to work with get_piece stuff for the Core Wheeler, which I made ages ago, which made use of a highly-modified version of Gengis_Khan's script for the BigWheel unit, which (kind've sort've) turned its wheels left or right depending on which way the unit was going. The Core Wheeler turned out OK, after lots and lots of tweaking, but I was never totally happy with it. I'll be happy to post the BOS if anybody wants to see it.
I need something simpler, more reliable, and self-contained- something that will return those three values based on simple, straightforward parameters.
Why do I want this kind of script? I plan to use this for a unit with a three-wheeled unit- a unit with two large wheels at the front, and one small one at the rear. If the rate of turn is greater than, say, 1 degree/second, then I want the rear wheel to turn in the opposite direction on the Y axis, and I want to make that turn directly proportional to the rate of turn.
2. How do I (again, reliably, simply if at all possible) determine the unit's current speed?
For this three-wheeled unit, I'd like to write up a script, that, based on speed, would rotate the front two wheels in opposite directions, if the unit is at a very low threshold speed and is turning. Such a script, if it could run cleanly (and reliably) would allow for me to do the same sort've trick with a truely animated tank track... another mini-project goal of mine.
3. Lastly... I'd like to hear input about how to make a transport that nearly-instantly releases all transported units, like most games that feature transports. I was thinking I'd basically equip the unit with an invisible point that would move using "now" to various points around the unit, and then return a TRUE value to the unit, allowing it to drop the units off, but I'm worried that this will just cause the unit to fruitlessly spin about, trying to align the point with whatever point has been selected for transport drop-point. Any input on this? I'd hate to go to the trouble to script it all up, just to find it didn't work as planned.
Advanced BOS scripting issues I would like input on.
Moderator: Moderators
Re: Advanced BOS scripting issues I would like input on.
1 and 3: see the rescripting of the SWTA transports that I made, specifically the imptroopc. (Because imptroopc is a wheeled transport that steers its eight wheels according to how it's turning, while rebtrans is a hover). Oh, and they're spring-tested.
3 is a bit complex, just copy and paste the script I used, copy the 3do pieces I added, and tweak the #defined values to your own liking. A better version of the transport script can be found in there, the best one available is there, and an even much better one is still on my HDD. But they're only tiny small improvement of the same thing. I also have a version where unit ID aren't stored but instead retrieved by looking which unit have same xz as the transport, which made it possible to auto-load and auto-unload 400 units in TA. However, most of that complex scripting is rendered useless by Spring zone-load zone-unload.
The basic idea for 1 is to use get XZ_ATAN(7) (yes, a constant number instead of a piece/unit XZ, that's the whole trick) to get the current orientation of the unit, then compare it with last orientation of the unit, then do some modulo 360° stuff so it doesn't get confused when doing for instance 359° - 1° = 2°
More details about 1 somewhere down here. Second post by me after the pictures with roads.
Hmm, actually I think I wrote it differently, instead of calculating the instant absolute angle of the unit and comparing with previous values of it, I just computed the angle toward the previous position, in the new local (tied to unit) axis system with a mere get XZ_ATAN(past_xz - present_xz).
As for 2, the MoveRateX used on imptroopc probably most won't work in Spring, so either:
- Try get CURRENT_SPEED, which is supposed to be supported since Spring 0.67b1.
- Use something similar than the angle measureing trick: Store regularly the position of PIECE_XZ(base), then do get XZ_HYPOT(current_xz_of_base - previous_xz_of_base)
Oh and have a look at that script that makes a bike unit bank when turning while you're at it, it's very small and calculate both speed and turning speed of the unit.
3 is a bit complex, just copy and paste the script I used, copy the 3do pieces I added, and tweak the #defined values to your own liking. A better version of the transport script can be found in there, the best one available is there, and an even much better one is still on my HDD. But they're only tiny small improvement of the same thing. I also have a version where unit ID aren't stored but instead retrieved by looking which unit have same xz as the transport, which made it possible to auto-load and auto-unload 400 units in TA. However, most of that complex scripting is rendered useless by Spring zone-load zone-unload.

The basic idea for 1 is to use get XZ_ATAN(7) (yes, a constant number instead of a piece/unit XZ, that's the whole trick) to get the current orientation of the unit, then compare it with last orientation of the unit, then do some modulo 360° stuff so it doesn't get confused when doing for instance 359° - 1° = 2°
More details about 1 somewhere down here. Second post by me after the pictures with roads.
Hmm, actually I think I wrote it differently, instead of calculating the instant absolute angle of the unit and comparing with previous values of it, I just computed the angle toward the previous position, in the new local (tied to unit) axis system with a mere get XZ_ATAN(past_xz - present_xz).
As for 2, the MoveRateX used on imptroopc probably most won't work in Spring, so either:
- Try get CURRENT_SPEED, which is supposed to be supported since Spring 0.67b1.
- Use something similar than the angle measureing trick: Store regularly the position of PIECE_XZ(base), then do get XZ_HYPOT(current_xz_of_base - previous_xz_of_base)
Oh and have a look at that script that makes a bike unit bank when turning while you're at it, it's very small and calculate both speed and turning speed of the unit.