unit scripting -> relative rotation and movement

unit scripting -> relative rotation and movement

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
MergeNine
Posts: 40
Joined: 15 Nov 2008, 00:55

unit scripting -> relative rotation and movement

Post by MergeNine »

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
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: unit scripting -> relative rotation and movement

Post by Tobi »

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 :-)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: unit scripting -> relative rotation and movement

Post by FLOZi »

Sounds right to me Tobi.
User avatar
MergeNine
Posts: 40
Joined: 15 Nov 2008, 00:55

Re: unit scripting -> relative rotation and movement

Post by MergeNine »

Brilliant, thanks I'll give that a shot.

:)
Post Reply

Return to “Game Development”