Page 1 of 1
gun barrel is lazy
Posted: 20 Apr 2014, 00:22
by zgames
I noticed something odd, while the unit can turn,fire,etc and seems to do fine, the gun barrel only rotates once per life time and then stays in that position. the turret it's self can rotate freely, but sometimes points the wrong way,resulting in the rounds being fired through the side or back. I am using the example mod from the tutorial on this site.
the unit looks similar to the one attached.
what should I look at and consider when determining the rotation?
Re: gun barrel is lazy
Posted: 20 Apr 2014, 00:53
by FLOZi
Script problem (post it)
Re: gun barrel is lazy
Posted: 20 Apr 2014, 00:54
by zgames
FLOZi wrote:Script problem (post it)
Code: Select all
local base = piece "base"
local body = piece "body"
local turret = piece "turret"
local gun = piece "gun"
local flare = piece "flare"
-- declares all the pieces we'll use in the script.
local SIG_AIM = 2
local RESTORE_DELAY = Spring.UnitScript.GetLongestReloadTime(unitID) * 2
-- picks a sensible time to wait before trying to turn the turret back to default.
function script.Create()
return 0
end
local function RestoreAfterDelay(unitID)
-- defines a local funtion to wait a bit, then move the turret back to how it was originally.
Sleep(RESTORE_DELAY)
Turn(turret, y_axis, 0, math.rad(35))
Turn(gun, x_axis, 0, math.rad(35))
end
function script.AimWeapon(weaponID, heading, pitch)
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
-- each time the Signal is called, all other functions with the same SignalMask will stop running. This makes sure the tank isn't trying to fire at something, and restore the turret position, at the same time.
Turn(turret, y_axis, heading, math.rad(35))
Turn(gun, x_axis, -pitch, math.rad(30))
WaitForTurn(turret, y_axis)
WaitForTurn(gun, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.FireWeapon(weaponID)
EmitSfx(flare, 0)
end
function script.QueryWeapon() return flare end
-- The piece that the bullet/laser/whatever comes out of.
function script.AimFromWeapon() return gun end
-- The unit looks from this piece down the QueryWeapon piece, to see whether it's aiming at anything.
function script.Killed(recentDamage, maxHealth)
return 0
end
function script.HitByWeapon(x,z,weaponDef,damage)
-- This stops the unit taking damage until it's been built.
if GetUnitValue(COB.BUILD_PERCENT_LEFT)>2 then return 0
else return damage
end
end
Re: gun barrel is lazy
Posted: 20 Apr 2014, 01:00
by FLOZi
Hmm, and you have the appropriately named pieces in the object?
Re: gun barrel is lazy
Posted: 20 Apr 2014, 01:10
by zgames
I have all 4 pieces, though "base" might not be what it should be
Re: gun barrel is lazy
Posted: 20 Apr 2014, 02:09
by FLOZi
Any errors in infolog.txt?
Re: gun barrel is lazy
Posted: 20 Apr 2014, 02:23
by zgames
FLOZi wrote:Any errors in infolog.txt?
there aren't any errors in infolog.txt.
things move and fire ok but it just looks very weird when the model doesn't cooperate
edit: I figured it out- I just had to indent them in Upspring