GPL Code Repository
Moderator: Moderators
-
- MC: Legacy & Spring 1944 Developer
- Posts: 1948
- Joined: 21 Sep 2004, 08:25
-
- MC: Legacy & Spring 1944 Developer
- Posts: 1948
- Joined: 21 Sep 2004, 08:25
- Guessmyname
- Posts: 3301
- Joined: 28 Apr 2005, 21:07
Simple script calculating the angle a unit turned
It's not a complete unit script but a small function get the real TurnAngle of a unit when it's turning, even when it's rotating in place. It doesn't need any other pieces on the model nor does it depend on a fixed refresh rate.
Can have various uses, I'm using it to reverse the tracks on a tank when it's turning and it works just fine (finally).
Also some thanks fly out to zwzsg, probably wouldn't be a bit further if he didn't explain some stuff to me (concerning XZ_ATAN) and KDR as well, that counter rawks
Code: Select all
// Add GPL header here, I'm lazy I know
#define ANIM_SPEED 37.5
TurnControl()
{
var RefreshRate, UnitHeading, TurnAngle;
RefreshRate = ANIM_SPEED;
UnitHeading = get XZ_ATAN(7); // XZ_ATAN(0) or any other small value do all return the angle from the current heading to the north. If the unit is facing to the north the angle is 0, if it is facing to the south it's 32768 (or 180° or <180>).
while (TRUE)
{
sleep RefreshRate;
UnitHeading = get XZ_ATAN(7) - UnitHeading; // This is the distance the unit turned after time RefreshRate. The value of UnitHeading can vary. The lower RefreshRate the smaller the value; the higher the TurnRate (in the FBI), the larger the value. edit: Changed this so that left is in the negatives and right is positive.
if (UnitHeading != 0) // UnitHeading is 0 when the unit stands still
{
// Reset if the directions change
if ((UnitHeading < 0 AND TurnAngle > 0) OR (UnitHeading > 0 AND TurnAngle < 0)) TurnAngle = 0;
// Adding to the angle over time
TurnAngle = TurnAngle + UnitHeading;
// Do stuff if TurnAngle >= 45° to the left
else if (TurnAngle <= -8192)
{
}
// Do stuff if TurnAngle >= 45° to the right
else if (TurnAngle >= 8192)
{
}
else
{
// Do stuff other stuff, like resetting something.
}
}
else
{
TurnAngle = 0;
// Do other stuff, like resetting something.
}
UnitHeading = get XZ_ATAN(7); // New last heading of the next iteration
}
}
Create()
{
...
start-script TurnControl();
}
Can have various uses, I'm using it to reverse the tracks on a tank when it's turning and it works just fine (finally).
Also some thanks fly out to zwzsg, probably wouldn't be a bit further if he didn't explain some stuff to me (concerning XZ_ATAN) and KDR as well, that counter rawks
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
-
- MC: Legacy & Spring 1944 Developer
- Posts: 1948
- Joined: 21 Sep 2004, 08:25