For lua unit scripting, should piece movement/rotation be relative to their local rotation rather than the 'world' axes? Or is there a separate way to script units to rotate or move relative to a normal determined within the script?
So you can see what I mean I've created a small experiment with a bit of script below, modifying a turret script (the armllt) so that it rotates along the y axis and the x axis then moves its barrel. I'd expect the barrel to move straight relative to it's new found rotation rather than along the z axis.
function script.Create()
c = 0
while ( c < 200) do --for testing
Turn(turret, y_axis, math.rad(-45), 0.5)
Turn(barrel, x_axis, -math.rad(-30), 0.25)
WaitForTurn(turret, y_axis)
WaitForTurn(barrel, x_axis)
Turn(turret, y_axis, math.rad(45), 0.5)
Turn(barrel, x_axis, -math.rad(30), 0.25)
WaitForTurn(turret, y_axis)
WaitForTurn(barrel, x_axis)
Sleep(100)
Move(barrel,z_axis, -5, 100)
WaitForMove(barrel, z_axis)
Move(barrel,z_axis, 5, 60)
WaitForMove(barrel, z_axis)
Sleep(500)
c = c +1
end
end
unit scripting -> relative rotation and movement
Moderator: Moderators
Re: unit scripting -> relative rotation and movement
Use code tags for code! Also I'm moving this to content creation/games & mods.
---
Movement of each piece is relative to its own coordinate system. (Which is, in turn, relative to its parents coordinate system, etc.)
Further, if I recall correctly, translation is applied before rotation, which would explain why your barrel moves along its original z-axis, rather than its rotated z-axis.
Rotation always happens around the origin of the local coordinate system, so if you translate first the piece may rotate around a point outside the piece.
To fix your issue introduce a (invisible) piece between barrel and turret. Then, rotating this piece will rotate the whole coordinate system for the barrel, so that moving the barrel along its z-axis will look fine.
I hope I got this correct as I can't check right now
---
Movement of each piece is relative to its own coordinate system. (Which is, in turn, relative to its parents coordinate system, etc.)
Further, if I recall correctly, translation is applied before rotation, which would explain why your barrel moves along its original z-axis, rather than its rotated z-axis.
Rotation always happens around the origin of the local coordinate system, so if you translate first the piece may rotate around a point outside the piece.
To fix your issue introduce a (invisible) piece between barrel and turret. Then, rotating this piece will rotate the whole coordinate system for the barrel, so that moving the barrel along its z-axis will look fine.
I hope I got this correct as I can't check right now
Re: unit scripting -> relative rotation and movement
Sounds right to me Tobi.
Re: unit scripting -> relative rotation and movement
Brilliant, thanks I'll give that a shot.
:)
:)