YouGroove Posted January 14, 2014 Posted January 14, 2014 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 Quote Stop toying and make games
Rick Posted January 14, 2014 Posted January 14, 2014 You only need self.target I think and not self.target.entity. The target is the entity already. Quote
YouGroove Posted January 14, 2014 Author Posted January 14, 2014 It's old GoblinAI code, so here is some code usefull for the WIKI 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. Quote Stop toying and make games
AggrorJorn Posted January 16, 2014 Posted January 16, 2014 If you don't want to let it check the code every frame update, then you can also use UpdatePhysics(). Quote
Rick Posted January 16, 2014 Posted January 16, 2014 Does doing a frame count on when to do a distance check really matter? Feels like you are trying to optimize something that doesn't really need it at this time, and possibly never. Quote
shadmar Posted January 16, 2014 Posted January 16, 2014 I still can't get this to work : http://www.leadwerks.com/werkspace/topic/8138-pointlight-viewrange-bug/ Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB
YouGroove Posted January 16, 2014 Author Posted January 16, 2014 @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. Quote Stop toying and make games
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.