AggrorJorn Posted January 12, 2010 Share Posted January 12, 2010 The titel might be a bit unclear but I couldn't think of anything else. I have a candle model which you can drag into the scene. Via the attached lua file I load the particles that are used to show a small flame on top of the candle. If I drag the candle in the editor everything works fine. In the fpscontroller script I load this model like the gun. The candle loads and positions itself fine, but the particles that create the light don't. It is like the lua file for the candle is not being used. Is it even possible to load a model via script and that the attached script runs with it? This is the script (before the loop): --candle candle = LoadMesh("abstract::candle.gmf",vwep) candle:SetParent(fw.main.camera,0) candle:SetPosition(Vec3(0.5,-0.5,1.35),0) Quote Link to comment Share on other sites More sharing options...
Rick Posted January 12, 2010 Share Posted January 12, 2010 ?? That's what I've been doing all along. Show us your entire candle lua file. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 12, 2010 Author Share Posted January 12, 2010 require("scripts/class") local class=CreateClass(...) function class:CreateObject(model) local object=self.super:CreateObject(model) --Create light object.light=CreatePointLight(4,model) object.light:SetColorf(1,0.6,0.25,1,1) object.light:SetPositionf(0,1.2,0,0) object.light:SetShadowOffset(0,0.91,0) object.fire=CreateEmitter(100,100,Vec3(0,1,0),0,object.model) object.fire:SetPositionf(0,0.5,0,0) object.fire:Paint(LoadMaterial('abstract::candleflame.mat'),0) object.fire:SetRadius(0.02,0.02) object.fire:SetColorf(0.2,0.2,0.2,1,1) object.fire:SetWaver(0) object.fire:SetVelocity(Vec3(0,0.01,0),Vec3(0,0.01,0)) --Declare initial values object.fluctuation=1.0 object.smoothedfluctuation=1.0 function object:SetKey(key,value) if key=="color" then elseif key=="intensity" then else return self.super:SetKey(key,value) end return 1 end function object:GetKey(key,value) if key=="color" then elseif key=="intensity" then else return self.super:GetKey(key,value) end return value end function object:Render() self.fluctuation=self.fluctuation+math.random(-100,100)/1000.0*AppSpeed() self.fluctuation=math.min(1.0,self.fluctuation) self.fluctuation=math.max(0.2,self.fluctuation) self.smoothedfluctuation=Curve(self.fluctuation,self.smoothedfluctuation,5.0/AppSpeed()) self.light:SetColorf(1.0*self.smoothedfluctuation,0.6*self.smoothedfluctuation,0.25*self.smoothedfluctuation,1,0) end end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 12, 2010 Author Share Posted January 12, 2010 Rick gave me the following advice via the chat: the lua scripts won't run if you load the object. the engine and editor has code in it to make the lua scripts run you should be able to place the candle in the scene still and when you run your game, move it to the fw.camera location and offset it slightly in front to give the same effect so in the candle lua file you can position the model relative to the camera Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 12, 2010 Author Share Posted January 12, 2010 briljant this works! It's not entirely perfect as the position sometimes changes when I go back from game mode to editor mode. However, I can just drag the candle inscreen when I'm done editing the level. here is the code I use and a screenie. function class:CreateObject(model) local object=self.super:CreateObject(model) --position candle at the camera object.model:SetPosition(fw.main.camera:GetPosition(1)) object.model:SetParent(fw.main.camera,0) object.model:SetPosition(Vec3(0.5,-0.5,1.35),0) The flame isn't final yet. It looks more like a stick of dynamite.... Quote Link to comment Share on other sites More sharing options...
Rick Posted January 12, 2010 Share Posted January 12, 2010 I like the feel of that. Very scary On a side note I'm guessing that the candle is like that even when in editor mode. Which obviously is a pain. This is why I make a global string value that I set in the main lua file that tells me if I'm in editor mode or game mode. That way when editing the object doesn't get in the way. 1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 12, 2010 Author Share Posted January 12, 2010 that would probably be better. When I'm more pro with coding I'll try that. for now I'll just stick with this. +1 for U. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 13, 2010 Share Posted January 13, 2010 You are loading the candle mesh in your code above. Call LoadModel() not LoadMesh(). Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
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.