gun barrel is lazy

gun barrel is lazy

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
zgames
Posts: 17
Joined: 04 Jul 2011, 07:32

gun barrel is lazy

Post 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?
Attachments
2014-04-19 18_25_22-Greenshot capture form.png
2014-04-19 18_25_22-Greenshot capture form.png (29.1 KiB) Viewed 1061 times
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: gun barrel is lazy

Post by FLOZi »

Script problem (post it)
zgames
Posts: 17
Joined: 04 Jul 2011, 07:32

Re: gun barrel is lazy

Post 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

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: gun barrel is lazy

Post by FLOZi »

Hmm, and you have the appropriately named pieces in the object?
zgames
Posts: 17
Joined: 04 Jul 2011, 07:32

Re: gun barrel is lazy

Post by zgames »

I have all 4 pieces, though "base" might not be what it should be
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: gun barrel is lazy

Post by FLOZi »

Any errors in infolog.txt?
zgames
Posts: 17
Joined: 04 Jul 2011, 07:32

Re: gun barrel is lazy

Post 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
Post Reply

Return to “Game Development”