Jump to content

Light Hide() Show()


YouGroove
 Share

Recommended Posts

Does this works with lights ? i have some code that makes game crash, perhaps i odn't use it well ?

 

Here si the script attached to a light (target is the player object like done in Camera script for example)

 



Script.minDistance = 5.0--float
Script.framecounter = 0
Script.target = nil--Entity "Target"



function Script:UpdateWorld()
       self.framecounter = self.framecounter +1 
    if self.framecounter > 10   then 
         local dist = self.entity:GetDistanceToEntity(self.target.entity)
          if dist > self.minDistance then
               self.entity:Hide()
         else
              self.entity:Show()
         end
         self.framecounter = 0
    end
end



Stop toying and make games

Link to comment
Share on other sites

It's old GoblinAI code, so here is some code usefull for the WIKI smile.png

 

 

Script.minDistance = 5.0--float
Script.framecounter = 0
Script.target = nil--Entity "Target"


function Script:UpdateWorld()
          self.framecounter = self.framecounter +1
          if self.framecounter > 10 then
                     local dist = self.entity:GetDistance(self.target)
                     if dist > self.minDistance then
                                self.entity:Hide()
                     else
                                self.entity:Show()
                     end
                     self.framecounter = 0
          end
end

 

Not the optimisation with framecounter : no need to check each frame, each 10 frames or more for some half second is enought.

Stop toying and make games

Link to comment
Share on other sites

@Rick: without optimisation, on the level when you see only 2 or 5 lights, it's displayed 10-15 or more are displayed and calculated, i increased frame rate from 10-17 to 25-40 with such FPS view.

 

You can check lights every half second, instead of each frame, so a counter helps.

Distance is not a lot eating CPU, but if you had to calculate some Navigation path to check something, indeed you will not call it each frame.

Stop toying and make games

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...