Jump to content

Script for Animating a Part of an Object **HELP**


02arnoldj
 Share

Recommended Posts

Hi im using the Leadwerks Engine 2.5 Evaluation ver. I could do with the Script to animate a part of an object, I.E The Windmill's Blades. Also How to animate a character in the engine ? I have a character and the animations work in the Model Viewer but not in the engine?

 

Thanks guys

 

JaMeS

Link to comment
Share on other sites

TY -We making Progress now,

 

We got the gun to animate in lua so we done a reload sequence that loads 3 sound files Clip being pulled the clip back in and the ****: Then we play them at key frames.

 

Now the thing we need to do is we need to make a script that we can use for any object that has animation files.

That script will play the ide frames of the object/Character.

 

I have look about all day I tried to make it up but get errors.

I saw you explained to some1 a way that referenced actor:Play actor:Draw

 

I tried the examples and I got errors again.

 

When a entity is placed into Editor Im guessing it builds up a table with location/Size ect does it contain frames I am using the crawler So We know it has them but do you need to tell it they are there.?

 

Is it possible to create scripts for characters in Lua that control AI of that character.

then in c load the scene and control cam using keys but the characters use there scripts so move around?

 

That way the AI will be Per Object and the game code becomes simple.

 

2 days to play gun animations! we could do with the help!

Link to comment
Share on other sites

Here is a character animation template i wrote for the leadwerks community project in lua

 

https://gist.github.com/friesencr/4743009

 

require("scripts/class")
require("scripts/math/math")
require("Scripts/constants/engine_const")
local class=CreateClass(...)
function class:CreateObject(model)
 local object=self.super:CreateObject(model)
local animation_data = {
 walk = {
  start = 50,
  frames = 23,
  multiplier = 1
 },
 idle = {
  start = 0,
  frames = 44,
  multiplier = 1
 },
 strafe = {
  start = 75,
  frames = 117 - 75,
  multiplier = 3
 },
 run = {
  start = 125,
  frames = 142 - 125,
  multiplier = 1
 },
 run_strafe = {
  start = 75,
  frames = 117 - 75,
  multiplier = 5
 },
 jump = {
  start = 150,
  frames = 176 - 150,
  multiplier = 1
 },
 land = {
  start = 210,
  frames = 214 - 210,
  multiplier = 1
 }
}
local current_frame
local animation_state
local animation_start_time = AppTime()
local current_animation = animation_data['idle']
function object:Update()
 local ca = current_animation
 local time = AppTime() - animation_start_time
 local frame = (( time / 60 ) % (ca.frames/ca.multiplier)) * ca.multiplier + ca.start
 self.model:Animate(frame, 0.2,0,1)
end
function SetAnimationState(state)
 animation_state = state
 animation_start_time = AppTime()
 current_animation = animation_data[state]
end
function object:ReceiveMessage(message, extra)
 if message == 'idle' then object:Idle()
 elseif message == 'walk' then object:Walk()
 elseif message == 'run' then object:Run()
 elseif message == 'jump' then object:Jump()
 elseif message == 'land' then object:Land()
 elseif message == 'strafe'  then object:Strafe()
 elseif message == 'run_strafe' then object:RunStrafe() end
end
function object:Walk()
 if animation_state ~= 'walk' then SetAnimationState('walk') end
end
function object:Idle()
 if animation_state ~= 'idle' then SetAnimationState('idle') end
end
function object:Run()
 if animation_state ~= 'run' then SetAnimationState('run') end
end
function object:Strafe()
 if animation_state ~= 'strafe' then SetAnimationState('strafe') end
end
function object:RunStrafe()
 if animation_state ~= 'strafe' then SetAnimationState('strafe') end
end
function object:Land()
 if animation_state ~= 'land' then SetAnimationState('land') end
end
function object:Jump()
 if animation_state ~= 'jump' then SetAnimationState('jump') end
end
end

Link to comment
Share on other sites

We got the gun to animate in lua so we done a reload sequence that loads 3 sound files Clip being pulled the clip back in and the ****: Then we play them at key frames.

 

Now the thing we need to do is we need to make a script that we can use for any object that has animation files.

That script will play the ide frames of the object/Character.

well if the animations are all in one file then you have to tell LE what frames are doing what animation... if the animations are separate files with similar names and loaded using LoadAnimation then you can probably make a generic animation script to work for any object. But just starting out with LE, you should probably focus on just understanding how LE works instead of trying to optimize a script to be used in any situation... Go through the link Josh provided and read it. Then read it again until you understand how animation works in LE. and then compare it to what Chris just provided.

 

I have look about all day I tried to make it up but get errors.

I saw you explained to some1 a way that referenced actor:Play actor:Draw

 

I tried the examples and I got errors again.

You need to realize there are two engines at the moment. LE2.5 is the evaluation version that you can currently download. LE3 is the rewritten engine that has not been released yet. 'actor:Play' & 'actor:Draw' are from LE3.

 

When a entity is placed into Editor Im guessing it builds up a table with location/Size ect does it contain frames I am using the crawler So We know it has them but do you need to tell it they are there.?

yes

 

Is it possible to create scripts for characters in Lua that control AI of that character.

then in c load the scene and control cam using keys but the characters use there scripts so move around?

yes

 

You and I assume your partner Mince have posted questions about the windmill model. That is not using animation sequences to rotate. The script is simply rotating a child mesh - blades- of the model. But I am curious on where you got that model from?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Guest Red Ocktober

if you're referring to the windmill in the old Leadwerks ( version 2.26 ? )... here's a lil bit of old code that i found when i did the same thing you're trying to do... the code is from an old experiment in object oriented programming in BlitzMax, so it's probably not relevant to the current version of Leadwerks... and then again, maybe it's still good...

 

anyways... there should be enough there and it should be obvious enough answer your question about getting that windmill to spin...

 

in short, i found the windmill object in the scene, then found the windmill blades (child object)... then spun it during the update...

 

 

Type TWindmill Extends TGameObject
Field picked :TPick
Field myLoc :TVec3
Field myRot :TVec3
Field listLink :TLink
Field wasPicked :TGameObject
Field lastSqueak :Int
Field squeak :TSound[]=[LoadSound("abstract::squeak_1.ogg"),LoadSound("abstract::squeak_2.ogg")]
Field foundChild :Int=0

Method Update(context:Object)

If GAME.GameObjectsList<>Null
' find the view cam location... were gonna need it in a sec
Local viewLoc:TVec3=EntityPosition(GAME.fw.Main.camera)
' find the windmill blades... they're gonna have to spin, not the whole windmill
Local theBlades:TEntity=FindChild(Self.mesh,"windmill_blades")

' get a link to the windmill in the gameobjects list
' so we can retrieve the value contained in the link
listLink=GAME.GameObjectsList.FindLink(Self)

' get the type of the object in the link in prep for pick test
 wasPicked= TGameObject(listLink.value())

' get the location of this object in case it is picked
 myLoc=EntityPosition (wasPicked.mesh)
 myLoc.y=myLoc.y+2

' only do the following block for this instance if in the list
' this is what makes each gameobject instance an individual
If Self
 If(TWindmill(context).mesh<>Null) Then TurnEntity theBlades,Vec3(0,GAME.windSpeed/5,0)

    ' Make the base squeak
    Local lasttime:Int=lastSqueak
    If (AppTime()-lasttime>3000)
    lastSqueak=AppTime()+ Rand(0,2000)
    EmitSound(theBlades,squeak[Rand(0,1)],80,1)
  EndIf
 EndIf
EndIf

EndMethod

 

sorry i can't be of more help... i just remember this vaguely from way back...

the cut and paste has the formatting all screwed up...

even though it's BlitzMax code it should be easy enough to see what's going on

and translate the relevant parts... the rest is just my OOP stuff and can be disregarded :)

 

--Mike

Link to comment
Share on other sites

Guest Red Ocktober

hey... me again... THANKS for posting your question... got me interested in moving the Windmill over to 2.5 and getting stuff working in lua only...

 

does your lua code look anything like this...

 

--Include the base script for all classes
require("scripts/class")
require("scripts/linkedlist")
require("scripts/table")
local class=CreateClass(...)
--Some global sounds we will use for all instances
squeak={}
squeak[0]=LoadSound("abstract::squeak_1.ogg")
squeak[1]=LoadSound("abstract::squeak_2.ogg")

--This function builds the interface for the properties editor
function class:InitDialog(grid)
--Add the base interface for all classes
self.super:InitDialog(grid)

  --Now we can add our own custom properties
  group=grid:AddGroup( "Windmill" )
  group:AddProperty( "spinspeed","|0,4",PROPERTY_FLOAT,"Spin Speed")
group:Expand(1)

end
function class:CreateObject(model)	  
 local object=self.super:CreateObject(model)	   
 function object:Render()					   
 --  frame = (AppTime()/35.0) % (300-0) + 1					   
 --  model:Animate( frame, 1,0, 1 )				
 end
end

--Spawn function for creating new instances
function class:CreateObject(model)
local entity=self.super:CreateObject(model)

--Retrieve a few limbs we will use later
entity.blades=model:FindChild("windmill_blades")
entity.base=model:FindChild("windmill_housing")
entity.model:SetKey("spinspeed","1")
--An update function for one instance.  Declaring the function as part of the entity table allows us to use "self" for the table
function entity:Update()

 --Although these limbs should always be present, it"s a good idea to add a check to make sure they exist before using them
 if self.blades~=nil then
  self.blades:Turnf(0,tonumber(self.model:GetKey("spinspeed"))*AppSpeed(),0,0)
 end

 if self.base~=nil then

  --Make the base sway slightly
  angle=math.sin(AppTime()/2000.0)*5-15
  angle=angle+math.cos(AppTime()/500.0)*2
  self.base:SetRotationf(0,0,angle,0)

  --Make the base squeak
  lasttime=tonumber(self.model:GetKey("lastsqueaktime","0"))
  if (AppTime()-lasttime>8000) then
   self.model:SetKey("lastsqueaktime",AppTime()+math.random(0,5000))
   self.base:EmitSound(squeak[math.random(0,1)],50,1,0)
  end
  lasttime=tonumber(self.model:GetKey("lastsheeptime","0"))
 end

end
end

--Update function, called during every UpdateWorld()
function Update(world)
if world==world_main then
 local model,entity
 for model,entity in pairs(entitytable) do
  if model.world==world then
   entity:Update()
  end
 end
 end
end

Link to comment
Share on other sites

Guest Red Ocktober

while getting it to work i was doin' some copying and pasting... that extra function snip should've been deleted...

 

hhhmmmm wonder why no error... looking now...

 

--Mike

Link to comment
Share on other sites

well here is just a simple version that uses the current standard object functions to show how to turn the windmill blades:

require("scripts/class")
local class=CreateClass(...)

function class:InitDialog(grid)
  self.super:InitDialog(grid)
  group=grid:AddGroup( "Windmill" )
  group:AddProperty( "spinspeed","|0,4",PROPERTY_FLOAT,"Spin Speed")
  group:Expand(1)
end

function class:CreateObject(model)
  local object = self.super:CreateObject(model)
  object.blades = model:FindChild("windmill_blades")
  object.model:SetKey("spinspeed","1")

  function object:Update()
     if self.blades~=nil then
        self.blades:Turn(Vec3(0,tonumber(self.model:GetKey("spinspeed"))*AppSpeed(),0))
     end
  end
end

 

granted due to the mesh heirarchy, about the only way this is useable is to have it converted directly from fbx... majority of the people here that use uu3d for conversion lose out on this nice little feature...

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Guest Red Ocktober

cool... and a lot cleaner...

 

*** edited ***

(i just found a version with 2 functions, similar to the one you just posted... it's been so long since i played with this, it's gonna take me a while to get back on track with this stuff)

 

 

hey... why can i not get the blades to spin if i load the scene from a lua script...

it works fine in the editor, bmax, c++ ??

 

 

--Mike

Link to comment
Share on other sites

Guest Red Ocktober

roger... copy...

 

thx

 

** edited ***

(yup... the abstract path was set to ""... setting it properly did the trick...

what a dope i am early in the morning)

 

--Mike

Link to comment
Share on other sites

Thanks Red & Macklebee. Got that done.

The aim was that if we can get a limb to rotate,

we could have a gun like a minigun with the barrels spinning but when we try this it come up with attempt to index a global =nil.

 

In the windmills case it uses class, and is a script of a object that has been dropped in the editor.

 

In this case We have a script that loads a gun and some sounds, and it all worked great.

We then made a minigun in 3dsmax and tried to adapt the windmill code to rotate the barrels. this is when we get the error

Link to comment
Share on other sites

Without seeing the actual model and script in question, all anyone can do is guess at what you are doing wrong. The windmill model this works correctly for... maybe there is a problem with your model. If you really want someone to help you, then zip up the model/script and post here.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

So the Lua Script following Will show the reload animation frames of smg.

the sound files are self explanatory -ly named.

 

The green parts are what we added to control reload/Fire/after some time lowers gun.

{R} = reload.

 

require("Scripts/constants/collision_const")

require("Scripts/constants/engine_const")

require("Scripts/LinkedList")

require("Scripts/filesystem")

require("Scripts/math/math")

require("scripts/classes/bullet")

 

--Variables

dx=0.0

dy=0.0

camerapitch=0.0

camerayaw=0.0

move=0.0

strafe=0.0

 

--gun

gun = 1

ammo = 0

maxammo = 36

gunfirefrequency = 1

gunout = 0

 

--frames

lastfiretime = 0.0

frame =175

reloadsequence = 82

reloadtime = reloadsequence

reload = 1

rstate = 0

bulletcase = 0

bcasetodrop = 0

shellv = 0

 

--Create a player controller

controller=CreateController(1.8,0.45,0.25,45)

controller:SetCollisionType(COLLISION_CHARACTER,0)

controller:SetPositionf(0,2,0,0)

controller:SetMass(10)

 

controller:SetPosition(fw.main.camera.position)

camerapitch=fw.main.camera.rotation.x

camerayaw=fw.main.camera.rotation.y

controller:Move(Vec3(0,-0.9,0))

 

local gunscale=0.6

local vwep = LoadMesh("abstract::vwep_hands.gmf")

 

--[[

local minigun = LoadMesh("abstract::minigun.gmf")

object.barrels = model:FindChild("barrels")

 

minigun:SetParent(fw.main.camera,0)

minigun:SetPosition(Vec3(-0.18*gunscale,-0.03*gunscale,0.37*gunscale),0)

minigun:SetScale(Vec3(0.04*gunscale,0.04*gunscale,0.04*gunscale))

local gundisplayposition = minigun:GetPosition()

 

LoadMesh("abstract::vwep_gun.gmf",vwep)

vwep:SetParent(fw.main.camera,0)

vwep:SetPosition(Vec3(-0.18*gunscale,-0.03*gunscale,0.37*gunscale),0)

vwep:SetScale(Vec3(0.04*gunscale,0.04*gunscale,0.04*gunscale))

local gundisplayposition = vwep:GetPosition()

 

sound_gunshot = LoadSound("abstract::gunshot.ogg")

source_gunshot = CreateSource(sound_gunshot)

source_gunshot:SetVolume(0.5)

 

 

--reload sections for precision!

sound_guncremove = LoadSound("abstract::cremove.ogg")

source_guncremove = CreateSource(sound_guncremove)

source_guncremove:SetVolume(0.5)

sound_guncreplace = LoadSound("abstract::creplace.ogg")

source_guncreplace = CreateSource(sound_guncreplace)

source_guncreplace:SetVolume(0.5)

sound_guncock = LoadSound("abstract::****.ogg")

source_guncock = CreateSource(sound_guncock)

source_guncock:SetVolume(0.5)

sound_guncempty = LoadSound("abstract::cempty.ogg")

source_guncempty = CreateSource(sound_guncempty)

source_guncempty:SetVolume(0.5)

sound_shelld1 = LoadSound("abstract::shelldrop1.ogg")

source_shelld1 = CreateSource(sound_shelld1)

source_shelld1:SetVolume(0.5)

sound_shelld2 = LoadSound("abstract::shelldrop2.ogg")

source_shelld2 = CreateSource(sound_shelld2)

source_shelld2:SetVolume(0.5)

sound_shelld3 = LoadSound("abstract::shelldrop3.ogg")

source_shelld3 = CreateSource(sound_shelld3)

source_shelld3:SetVolume(0.5)

 

 

sound_shellr1 = LoadSound("abstract::shellroll1.ogg")

source_shellr1 = CreateSource(sound_shellr1)

source_shellr1:SetVolume(0.5)

 

 

sound_shellr2 = LoadSound("abstract::shellroll2.ogg")

source_shellr2 = CreateSource(sound_shellr2)

source_shellr2:SetVolume(0.5)

 

 

sound_shellr3 = LoadSound("abstract::shellroll3.ogg")

source_shellr3 = CreateSource(sound_shellr3)

source_shellr3:SetVolume(0.5)

 

 

vwep :SetShadowMode(0,1)

local displayposition=Vec3(-0.26/2.0,-0.03,0.19)

local muzzleflash = CreatePointLight(9)

muzzleflash:SetParent( vwep )

muzzleflash:SetColor(Vec4(1,0.6,0.0,1.0))

muzzleflash:SetPosition( displayposition )

muzzleflash:SetShadowMode(0)

 

--c=CreateCube(fw.main.camera)

--c:SetPositionf(0,0,5)

 

HideMouse()

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

FlushKeys()

FlushMouse()

 

local pick

local camera = fw.main.camera

local remainingtime

local starttime=AppTime()

local gameduration=2--length of game in minutes

local gamemode=0

 

gunpos = vwep.position:Copy()

 

local smoothedgunswayamplitude=0.0

local smoothedgunswayspeed =0.0

local guntime = 0.0

local recoil = 0.0

local lastfiretime=0.0

local smoothrecoil=0.0

local swaydamping=0.0

local smoothswaydamping=0.0

local lightsmoothing =0.0

local gunlight = 0.0

 

--Flashlight

flashlight = {}

flashlight.light = CreateSpotLight(8)

flashlight.light:Hide()

flashlight.sound_switch = LoadSound("abstract::switch.wav")

flashlight.state=0

flashlight.light:SetConeAngles(30,35)

flashlight.light:SetRotation(Vec3(5,0,0))

flashlight.light:SetShadowmapSize(512)

flashlight.light:Paint(LoadMaterial("abstract::flashlight.mat"))

 

function flashlight:SetState( state )

if state~=self.state then

self.state=state

if state==0 then

self.light:Hide()

else

self.light:Show()

end

if self.sound_switch~=nil then

self.sound_switch:Play()

end

end

end

 

 

function ShootBullet( position, direction )

-- local speed=100.0

-- local pick = LinePick( position, Vec3(position.x+direction.x * speed) )

end

 

flashlight.light:Show()

flashlight.light:Hide()

 

 

 

 

 

 

 

 

 

 

--Main Loop

while KeyHit(KEY_ESCAPE)==0 do

 

 

--Shell Casing Sound Controll

--shellr1

--shelld1

if bcasetodrop >0 then

bcasetodrop = bcasetodrop - 1

 

shellv = math.random(1,5)

 

if shellv ==1 then

source_shelld1:Play()

source_shellr1:Play()

end

 

if shellv ==2 then

source_shelld2:Play()

source_shellr2:Play()

end

 

if shellv ==3 then

source_shelld3:Play()

source_shellr3:Play()

end

 

if shellv ==4 then

source_shelld1:Play()

source_shellr3:Play()

end

 

if shellv ==5 then

source_shelld2:Play()

source_shellr1:Play()

end

 

 

end

 

 

jump=KeyHit(KEY_SPACE)*6.0

if controller:IsAirborne()==1 then jump=0 end

 

 

local time = AppTime()/3200.0

--local frame = time*(179.0-96.0)+96.0

--frame=Clamp( frame, 96, 179 )

--vwep:Animate(96,1,0,1)

 

--if KeyDown(KEY_LCONTROL)==1 then

-- controller:Crouch(1)

--else

-- controller:Crouch(0)

--end

 

--b:SetPositionf(math.sin(AppTime()/1000.0)*10+10,0,0)

 

--Camera look

gx=Round(GraphicsWidth()/2)

gy=Round(GraphicsHeight()/2)

dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())

dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())

MoveMouse(gx,gy)

camerapitch=camerapitch+dy

camerayaw=camerayaw-dx

camerapitch=math.min(camerapitch,90)

camerapitch=math.max(camerapitch,-90)

fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

 

movespeed=6

movesmoothing=10

if controller:IsAirborne()==1 then

movesmoothing=200

end

 

--Player movement

move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing/AppSpeed())

strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing/AppSpeed())

 

--Use objects

if KeyHit(KEY_E)==1 then

pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0)

if pick~=nil then

repeat

if pick.entity:GetClass()==ENTITY_MODEL then

break

end

pick.entity=pick.entity.parent

until pick.entity==nil

if pick.entity~=nil then

pick.entity:SendMessage("use",controller,0)

end

end

end

 

--Update controller

controller:Update(camerayaw,move,strafe,jump,40,1,KeyDown(KEY_LCONTROL))

fw:Update()

 

if KeyHit(KEY_F)==1 then

flashlight.state=1-flashlight.state

if flashlight.state==0 then

flashlight.light:Hide()

else

flashlight.light:Show()

end

if flashlight.sound_switch~=nil then

flashlight.sound_switch:Play()

end

-- flashlight:SetState(1-flashlight.state)

end

 

--Position camera

local h=1.7

if controller.crouchmode==1 then

h=1.8*(2.0/3.0)-0.1

end

camera:SetPositionf(controller.position.x,Curve(controller.position.y+h,camera.position.y,2.0/AppSpeed()),controller.position.z,1)

 

time=AppTime()

gunfirefrequency=80

gunswayspeed=0.001*20.0

gunoffset = gunpos:Copy()

gunswayamplitude = 0.02

if KeyDown(KEY_W)==1 or KeyDown(KEY_D)==1 or KeyDown(KEY_A)==1 or KeyDown(KEY_S)==1 then

gunswayamplitude = 0.03

gunswayspeed=0.005*20.0

end

 

smoothedgunswayamplitude = Curve( gunswayamplitude, smoothedgunswayamplitude,8.0 )

smoothedgunswayspeed = Curve( gunswayspeed, smoothedgunswayspeed,8.0 )

 

if smoothrecoil<0.001 then

guntime = guntime + AppSpeed() * smoothedgunswayspeed * math.max(0.0,1.0 - smoothswaydamping)

end

 

--collectgarbage(collect)

 

gunoffset.z = gunoffset.z - smoothrecoil * 0.05

--smoothedgunswayamplitude = smoothedgunswayamplitude * (1.0 - smoothswaydamping)

gunoffset.x = gunoffset.x + math.sin( guntime ) * smoothedgunswayamplitude * gunscale

gunoffset.y = gunoffset.y + (1.0-math.cos( guntime*2.0 )) * 0.005 * gunscale-- * math.min(1.0,1.0 - smoothswaydamping))

vwep:SetPosition( gunoffset )

recoil = recoil-0.1

swaydamping = math.max( swaydamping - 0.05, 0.0 )

recoil = math.max(recoil,0.0)

smoothrecoil=Curve(recoil,smoothrecoil,3.0)

smoothswaydamping = Inc( swaydamping ,smoothswaydamping,0.01 )

gunlight = math.max( gunlight- 0.2, 0.0 )

lightsmoothing =gunlight-- Curve(gunlight,lightsmoothing,8.0)

muzzleflash:SetColor(Vec4(1.0*lightsmoothing,0.6*lightsmoothing,0.0,1.0))

if lightsmoothing <0.01 then

muzzleflash:Hide()

end

 

--if gunout == 1 then

 

if gun==1 then

--Reload

if KeyDown(KEY_R)==1 then

if ammo < maxammo then

reload =1

 

end

end

 

 

--190 = lower gun for switch

--fire gun = 70

 

 

--Reload Sequence!

if reload == 1 then

vwep:Animate( 176 - reloadtime,1,0,1)

reloadtime = reloadtime - AppSpeed()/2

 

if rstate == 0 then

if reloadtime - 62 <2 then

source_guncremove:Play()

rstate = 1

end

end

 

if rstate == 1 then

if reloadtime - 25 <2 then

source_guncreplace:Play()

rstate = 2

end

end

 

if rstate == 2 then

if reloadtime - 10 <2 then

source_guncock:Play()

rstate = 10

end

end

 

 

if reloadtime < 0.0 then

reloadtime=reloadsequence

reload = 0

rstate = 0

ammo = maxammo

end

end

 

end

 

 

--Fire weapon

if MouseDown(1)==1 then

 

if gun==2 then

-- if self.barrels~=nil then

-- self.barrels:Turn(Vec3(0,1*AppSpeed(),0))

-- end

end

 

if gun==1 then

 

if AppTime()-lastfiretime > gunfirefrequency then

if ammo > 0 then

bulletcase = 1

bcasetodrop = bcasetodrop +1

frame =91

ammo = ammo -1

recoil = 1.0

lastfiretime=AppTime()+math.random(0,20)

gunswayspeed=0.0

gunlight = 1.0

source_gunshot:Play()

source_gunshot:SetPitch(1.0 + (math.random()-0.5)*0.05 )

swaydamping = 1.0

muzzleflash:Show()

 

CreateBullet(vwep:GetPosition(1) , fw.main.camera.mat:K():Scale(300))

end

 

if reload == 0 then

if ammo <1 then

if AppTime()-lastfiretime > gunfirefrequency then

lastfiretime=AppTime()+math.random(0,20)

sound_guncempty:Play()

source_guncempty:SetPitch(1.0 + (math.random()-0.5)*0.05 )

end

end

end

 

end

end

 

if reload ==0 then

if bulletcase==1 then

frame = frame +AppSpeed()/3

vwep:Animate( frame,1,0,1)

--91 > 100 for shell eject frames

if frame >96 then

bulletcase = 0

frame = 180

end

end

end

 

 

 

 

--Relax Gun After No Fire for while!

if AppTime()-lastfiretime >10000 then

if bulletcase==0 then

if reload==0 then

if frame < 183 then

frame = frame + AppSpeed()/10

vwep:Animate( frame,1,0,1)

end

end

end

end

 

--end

--gunout=1

end

 

 

 

UpdateBullets()

 

flashlight.light:SetPosition(fw.main.camera:GetPosition(1))

flashlight.light:SetRotationf( CurveAngle( fw.main.camera.rotation.x, flashlight.light.rotation.x, 3.0/AppSpeed() ), CurveAngle( fw.main.camera.rotation.y, flashlight.light.rotation.y, 3.0/AppSpeed() ) )

flashlight.light:Movef(-0.07,-0.04,0.02)

 

--c:SetParent(nil,1)

fw:Render()

--c:SetParent(fw.main.camera,1)

 

 

Flip(0)

 

end

 

controller:Free()

vwep:Free()

 

ShowMouse()

 

then we added the minigun bits

Link to comment
Share on other sites

--added to top

local minigun = LoadMesh("abstract::minigun.gmf")

 

 

--tried it with requires script& class = create script

--that didnt work either.

 

 

-added at top

object.barrels = model:FindChild("barrels")

 

minigun:SetParent(fw.main.camera,0)

minigun:SetPosition(Vec3(-0.15*gunscale,-0.04*gunscale,0.25*gunscale),0)

minigun:SetScale(Vec3(0.03*gunscale,0.03*gunscale,0.03*gunscale))

local gundisplayposition = minigun:GetPosition()

 

 

 

--Added to main loop

if MouseDown(1)==1 then

if gun==2 then

if self.barrels~=nil then

self.barrels:Turn(Vec3(0,1*AppSpeed(),0))

end

end

end

Link to comment
Share on other sites

local minigun = LoadMesh("abstract::minigun.gmf")
object.barrels = model:FindChild("barrels")

 

Since you are loading the mesh just be aware that this does not load the minigun's object script. The next line does not work because this is a game script and not an object script. So 'object.barrels' means nothing and model is not referencing the minigun.

 

If you are trying to find the child mesh in the minigun GMF then you have to reference the minigun

local minigun = LoadMesh("abstract::minigun.gmf")
local barrels = minigun:FindChild("barrels")

You should still post the model to confirm that you have mesh hierarchy in the GMF. Also this can be verified in the modelviewer and you can do a logic check to make sure its found by checking to make sure barrels is not equal to nil.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

are you still using 'object.barrels' in the game script? if so, stop it and do what i showed you to do.

 

if you are getting the error because 'barrels' is actually nil then you need to perform a logic check to see if it actually found the child mesh called 'barrels'. If this is happening then I can assume your model doesnt actually have mesh hierarchy.

 

and you should try to make a simpler standalone version that just focuses on loading the minigun and finding the child mesh if it exists.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...