Tommek Posted September 8, 2014 Share Posted September 8, 2014 Hi Guys, I've made myself a really simple LOD Script in Lua. Script.Player = "" --entity "Player Entity" Script.ViewDistanceMin = 10 --float "View Distance Min" Script.ViewDistanceMax = 100 --float "View Distance Max" function Script:Start() self.entity:Hide() end function Script:UpdateWorld() if (self.entity:GetDistance(self.Player) < self.ViewDistanceMax and self.entity:GetDistance(self.Player) > self.ViewDistanceMin) then self.entity:Show() else self.entity:Hide() end end So for an instance I want to use this, I create 3 different models (HD, SD, Low) and give them distances like: HD 0/9.0, SD 9.1/25.0, Low 25.1/2000.0 My problem here is the switchover that is not really smooth. Because if the player entity is slow you see the flickering. If I set the distances equal they overlap. The overlapping is quite ok. But is there a possibility to make a smooth morph? 1 Quote Link to comment Share on other sites More sharing options...
metaldc4life Posted September 8, 2014 Share Posted September 8, 2014 Sweet thanks!!!! Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 I see obvious LOD switching in AAA games still. A possible thing to look into is maybe fading out the old model and fading in the new one? Not sure how that would look, but it would be smoother. Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 Yeah I will try to get some fading running. But as it seems It is not really usuable in LUA. My demo Level takes forever to start (17 entites with 3 detail levels), but after that it seems to run nice. Could someone test this in C++? I'm just looking for the last push to buy myself a c++ License Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 8, 2014 Share Posted September 8, 2014 You might want to add some frequency timer. 2 or 3 times a second to check the distance is more than a enough. Also in your if statement you calculate the same distance twice. If you store it befor the if statement, you save another calculation. 1 Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 Nice Ideas! EDIT: But as I said, after the start its working nice. I think it takes so lang to initialize the scripts mutiple times. is this correct? Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 Script.Player = "" --entity "Player Entity" Script.ViewDistanceMin = 10 --float "View Distance Min" Script.ViewDistanceMax = 100 --float "View Distance Max" Script.DistancePollTime = 3 --int "Secs Poll Distance" Script.PollTimer = 0 function Script:Start() self.entity:Hide() end function Script:UpdateWorld() self.PollTimer = self.PollTimer + (Time:GetSpeed()/100) if (self.PollTimer > self.DistancePollTime) then self.Distance = self.entity:GetDistance(self.Player) if (self.Distance < self.ViewDistanceMax and self.Distance > self.ViewDistanceMin) then self.entity:Show() else self.entity:Hide() end self.PollTimer = 0 end end I've added Aggrors ideas, but now I get: 18 : error in function 'GetDistance'.; argument #2 is 'string'; 'Entity' expected. Why did this change the context? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 8, 2014 Share Posted September 8, 2014 The scripts are are very simple and don't cost much. What costs a lot of time is the loading of all those models and textures. THere was this unofficial function that allows to load textures dynamically. Can't find it right now. Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 You must not have filled in the Script.Player setting in the editor with anything. You init it as a string but call it an --entity. If I use --entity I usually init with a nil. Even so you'd then get a nil value for self.Player error but maybe that would make more sense to tell you that you forgot to assign an entity in the editor for that property. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 8, 2014 Share Posted September 8, 2014 Try this as well: local distance = self.entity:GetDistance(self.Player) Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 local Distance = self.entity:GetDistance(self.Player) if (Distance < self.ViewDistanceMax and Distance > self.ViewDistanceMin) then Same error. Do I have to call self.Player in a different way inside the if-statement? Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 Did you actually drag an entity in the editor over the Player property of that script? To me it sounds like you did not and so self.Player = "" which is the error you are getting (expecting entity got string) Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 Yes I did. I checked several times. And even tried with only one of my LOD entities. Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 Can you post a screenshot, but that's what that error is saying. Would have to see how you have this all setup. Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 8, 2014 Author Share Posted September 8, 2014 "Box 2" is now the only asset using the script. I don't get it. Quote Link to comment Share on other sites More sharing options...
josk Posted September 8, 2014 Share Posted September 8, 2014 Change Script.player = "" --entity "Player Entity" --to Script.player = nil --entity "Player Entity" "" = string Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 8, 2014 Share Posted September 8, 2014 If you print out the value of Player to screen what do you get? System:Print(self.Player) Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 What is Player in your scene? Is it more csg or is it the actual player prefab that comes with Leadwerks? If it's just csg then without mass or a script attached csg gets collapsed (meaning you can't reference it anywhere), so that may make sense with the error as it wouldn't exist when you start it up and so it wouldn't be able to set Player which leaves it as it's initial value of an empty string. If it is the player prefab then we have other issues and print out what it is like Aggror mentions Quote Link to comment Share on other sites More sharing options...
shadmar Posted September 8, 2014 Share Posted September 8, 2014 Try : System:Print(self.player:GetClassName()) if not an entity, cast it to an entity self.player=tolua.cast(self.player,"Entity") Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Tommek Posted September 9, 2014 Author Share Posted September 9, 2014 I am using the Player PreFab. Will try the suggestions when back at home. Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 9, 2014 Author Share Posted September 9, 2014 Really weird. I've created a new Test Project. I just copied the script 1:1 and it is working?! Quote Link to comment Share on other sites More sharing options...
Tommek Posted September 9, 2014 Author Share Posted September 9, 2014 Tested it again on the machine from yesterday. The same project, now it works... "Have you tried turning it off and on again?" Quote 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.