View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001920 | Spring engine | Lua | public | 2010-05-10 01:48 | 2010-05-10 17:01 |
| Reporter | das bruce | Assigned To | |||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | no change required | ||
| Product Version | 0.81.2 | ||||
| Summary | 0001920: Turn command turns wrong way if unit doesn't move between orders | ||||
| Description | I have a builder which is supposed to turn towards its target construction before being built, it does this fine the first time, but if it doesn't move between constructions it will turn the piece the opposite direction that it is supposed to. Additional Information contains the script for the unit. turnHack is the variable I use to compensate for this odd behaviour. | ||||
| Additional Information | local body, shovel, nanogun1, nano, nanogun2, nano2, dish = piece ("body", "shovel", "nanogun1", "nano", "nanogun2", "nano2", "dish") --constants local SIG_AIM = 2 local SIG_BUILD = 4 local RESTORE_DELAY = 2000 local rad = math.rad local pi = math.pi local TURNRATE = 2 local HEADING = 82 --Calls for Effects. If you get more effects just add SFX.CEG + 1, SFX.CEG + 2 and so on... -- local orc_hand_glow = SFX.CEG -- local orc_orange_glow = SFX.CEG +1 --includes include "rockunit.lua" include "smokeunit.lua" include "include/dishspin.lua" function script.Create(unitID) turnHack = 1 StartThread(DishSpin(dish)) end local function RestoreAfterDelay(unitID) -- Sleep(RESTORE_DELAY) end function script.StartBuilding(heading, pitch) Signal(SIG_BUILD) SetSignalMask(SIG_BUILD) originalHeading = GetUnitValue(HEADING)*pi/32768 --save the original heading Turn(body, y_axis, heading*turnHack, TURNRATE) --turn the base piece to face the construction (takes time) Turn(shovel, x_axis, rad(-10), TURNRATE) WaitForTurn(body, y_axis) Turn(body, y_axis, 0) --Rapidly flick back to the original heading and then Spring.SetUnitRotation(unitID, 0, -(originalHeading+heading), 0 ) WaitForTurn(shovel, x_axis) SetUnitValue(COB.INBUILDSTANCE, 1) turnHack = -1 return 1 end function script.StopBuilding() Signal(SIG_BUILD) SetSignalMask(SIG_BUILD) SetUnitValue(COB.INBUILDSTANCE, 0) Turn(shovel, x_axis, 0, TURNRATE) return 0 end function script.StartMoving() turnHack = 1 end function script.StopMoving() end function script.QueryNanoPiece() return nanogun1 end --Pieces that fly off when unit is destroyed. Other pieces disappear! function script.Killed(recentDamage, maxHealth) return 1 end | ||||
| Tags | No tags attached. | ||||
| Checked infolog.txt for Errors | |||||
|
|
There is nothing odd about it, you just don't seem to understand angles. A). the heading argument passed to StartBuilding() is the relative signed difference between the unit's own heading and the heading toward the position of the to-be-built object. B) Unit headings are represented with respect to a fixed coordinate system. C). Turn() does not change the heading of the unit, just of the piece it is called on. Assume the initial unit and body headings are 0 (--> due SOUTH), and the first buildee position is south-EAST of the unit (for a relative angular gap of +45 degrees). Therefore... StartBuilding(heading = +45, irrelevant) 1. originalHeading = GetUnitValue(HEADING) * pi/32768 2. Turn(body, y_axis, heading, TURNRATE) [without hack] 3. WaitForTurn(body, y_axis) 4. Turn(body, y_axis, 0) 5. Spring.SetUnitRotation(unitID, 0, -(originalHeading+heading), 0 ) ...after [3] the unit's new heading is still originalHeading (0), but visually appears to be pointing in a different direction because the body piece has turned. [4] has no effect on the unit's heading either, it just resets the body piece orientation to 0. [5] then actually *does* change the heading (but *not* the piece orientations, which are relative to the unit) from 0 to -(0 + 45) = -45 to point the unit toward the first buildee. Now assume the second buildee is due EAST, so StartBuilding is again called with heading = +45. The new <originalHeading> will be -45, and thus SetUnitRotation will now flip the heading to -(-45 + 45) = 0 degrees, changing it from south-EAST back to SOUTH which is the opposite of what you want. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2010-05-10 01:48 | das bruce | New Issue | |
| 2010-05-10 16:38 | Kloot | Note Added: 0004901 | |
| 2010-05-10 16:47 | Kloot | Note Edited: 0004901 | |
| 2010-05-10 16:47 | Kloot | Note Edited: 0004901 | |
| 2010-05-10 16:48 | Kloot | Status | new => closed |
| 2010-05-10 16:48 | Kloot | Resolution | open => no change required |
| 2010-05-10 17:00 | Kloot | Status | closed => new |
| 2010-05-10 17:00 | Kloot | Resolution | no change required => reopened |
| 2010-05-10 17:00 | Kloot | Note Edited: 0004901 | |
| 2010-05-10 17:01 | Kloot | Status | new => closed |
| 2010-05-10 17:01 | Kloot | Resolution | reopened => no change required |