HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Smooth Banked Turns Trigger

05-26-2007, 03:07 AM#1
Dark.Revenant
I'm making a map that will include space fighters that bank realistically with smooth turns. Right clicking a location will make the fighter start turning toward that angle. The trigger for finding whether the turn should be clockwise or counter clockwise works perfectly.

However, this trigger (a chunk from a trigger that picks every fighter and then does actions (it's leak-free, so don't worry)) doesn't work properly. It's supposed to make the fighters move and turn realistically, using variables for the current speed, turning rate, current angle, and the target angle for turning. The trigger almost works perfectly. When the fighter is told to turn to any angle from 0-180 degrees (northern hemisphere), it is completely flawless. When the fighter moves counter clockwise to the southern hemisphere, everything is just dandy as well. It's when the fighter moves clockwise to any point in the southern hemisphere when things go wrong. Sometimes the ship will instantly snap to the target angle rather than gradually get there. Other times the ship will go into an infinite circle pattern, turning indefinitely until I tell it to turn to the northern hemisphere.

I've tried a dozen times to resolve this issue, sometimes completely rewriting the code. Unfortunately, the effect has hardly improved. I, for the life of me, can't figure out what is wrong. Thus I post this chunk of my trigger here so that someone more observant can figure out what the hell is up with it: (This trigger is run 50 times each second)

Trigger:
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AShipClockwise[(Custom value of (Picked unit))] Equal to True
AShipAngle[(Custom value of (Picked unit))] Greater than 180.00
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AIsTurning[(Custom value of (Picked unit))] Equal to True
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AShipAngle[(Custom value of (Picked unit))] Less than or equal to (ATargetAngle[(Custom value of (Picked unit))] + (AShipTurning[(Custom value of (Picked unit))] / 50.00))
AShipAngle[(Custom value of (Picked unit))] Greater than or equal to (ATargetAngle[(Custom value of (Picked unit))] - (AShipTurning[(Custom value of (Picked unit))] / 50.00))
Collapse Then - Actions
Set AShipAngle[(Custom value of (Picked unit))] = ATargetAngle[(Custom value of (Picked unit))]
Set AIsTurning[(Custom value of (Picked unit))] = False
Collapse Else - Actions
Set AShipAngle[(Custom value of (Picked unit))] = (AShipAngle[(Custom value of (Picked unit))] - (AShipTurning[(Custom value of (Picked unit))] / 50.00))
Collapse Else - Actions
Do nothing
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AShipClockwise[(Custom value of (Picked unit))] Equal to True
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AIsTurning[(Custom value of (Picked unit))] Equal to True
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
(Abs((AShipAngle[(Custom value of (Picked unit))] - ATargetAngle[(Custom value of (Picked unit))]))) Less than or equal to (AShipTurning[(Custom value of (Picked unit))] / 25.00)
(Abs((AShipAngle[(Custom value of (Picked unit))] - ATargetAngle[(Custom value of (Picked unit))]))) Greater than or equal to (360.00 - (AShipTurning[(Custom value of (Picked unit))] / 25.00))
Collapse Then - Actions
Set AShipAngle[(Custom value of (Picked unit))] = ATargetAngle[(Custom value of (Picked unit))]
Set AIsTurning[(Custom value of (Picked unit))] = False
Collapse Else - Actions
Set AShipAngle[(Custom value of (Picked unit))] = (AShipAngle[(Custom value of (Picked unit))] - (AShipTurning[(Custom value of (Picked unit))] / 50.00))
Collapse Else - Actions
Do nothing
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AIsTurning[(Custom value of (Picked unit))] Equal to True
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
(Abs((AShipAngle[(Custom value of (Picked unit))] - ATargetAngle[(Custom value of (Picked unit))]))) Less than or equal to (AShipTurning[(Custom value of (Picked unit))] / 25.00)
(Abs((AShipAngle[(Custom value of (Picked unit))] - ATargetAngle[(Custom value of (Picked unit))]))) Greater than or equal to (360.00 - (AShipTurning[(Custom value of (Picked unit))] / 25.00))
Collapse Then - Actions
Set AShipAngle[(Custom value of (Picked unit))] = ATargetAngle[(Custom value of (Picked unit))]
Set AIsTurning[(Custom value of (Picked unit))] = False
Collapse Else - Actions
Set AShipAngle[(Custom value of (Picked unit))] = (AShipAngle[(Custom value of (Picked unit))] + (AShipTurning[(Custom value of (Picked unit))] / 50.00))
Collapse Else - Actions
Do nothing
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AShipAngle[(Custom value of (Picked unit))] Greater than or equal to 360.00
Collapse Then - Actions
Set AShipAngle[(Custom value of (Picked unit))] = (AShipAngle[(Custom value of (Picked unit))] - 360.00)
Collapse Else - Actions
Do nothing
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AShipAngle[(Custom value of (Picked unit))] Less than 0.00
Collapse Then - Actions
Set AShipAngle[(Custom value of (Picked unit))] = (AShipAngle[(Custom value of (Picked unit))] + 360.00)
Collapse Else - Actions
Do nothing
Set TempPoint1 = (Position of (Picked unit))
Set TempPoint2 = (TempPoint1 offset by (AShipSpeed[(Custom value of (Picked unit))] / 50.00) towards AShipAngle[(Custom value of (Picked unit))] degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of TempObject) Equal to Interceptor
Collapse Then - Actions
Set TempPoint3 = (TempPoint1 offset by (AShipSpeed[(Custom value of (Picked unit))] / 1.00) towards AShipAngle[(Custom value of (Picked unit))] degrees)
Set TempPoint4 = (TempPoint2 offset by 50.00 towards (AShipAngle[(Custom value of (Picked unit))] + 172.00) degrees)
Unit - Move AEngineTrail1[(Custom value of (Picked unit))] instantly to TempPoint4, facing AShipAngle[(Custom value of (Picked unit))] degrees
Custom script: call RemoveLocation( udg_TempPoint4 )
Set TempPoint4 = (TempPoint2 offset by 50.00 towards (AShipAngle[(Custom value of (Picked unit))] + 188.00) degrees)
Unit - Move AEngineTrail2[(Custom value of (Picked unit))] instantly to TempPoint4, facing AShipAngle[(Custom value of (Picked unit))] degrees
Custom script: call RemoveLocation( udg_TempPoint4 )
Camera - Pan camera for Player 1 (Red) to TempPoint3 over 0.25 seconds
Collapse Else - Actions
Do nothing
Unit - Move (Picked unit) instantly to TempPoint2, facing AShipAngle[(Custom value of (Picked unit))] degrees

Anyone who can help me gets a full plate of cookies!
05-26-2007, 03:35 AM#2
Ammorth
God, GUI is so ugly to follow.

Some advice though, make sure your angles are between the bounds you think they should be (either 0 to 360 or -180 to 180) and if they aren't add/subtract 360 till they are.
05-26-2007, 03:55 AM#3
Dark.Revenant
Thats exactly what the bottom part does.
05-26-2007, 05:42 AM#4
grim001
Please just give up this ill-concieved way of doing it. Instead learn JASS and vJASS and use my physics engine when it comes out in a few weeks. This isn't really creating the effect of momentum which is what you should be looking for with spaceships anyway.