Skrakle Posted May 26, 2015 Share Posted May 26, 2015 I'm using a brush to make an elevator, while it goes up, it's flickering, like it's trying to drop back down, i would have thought SetGravityMode(false) would have prevented this. Is there way to eliminate this effect? Script.Trigger_Delay = 500; --int "Triggering delay" Script.is_active = 0; Script.timer = 0; function Script:Start() self.entity:SetMass(10000) self.entity:SetGravityMode(false) self.entity:SetCollisionType(Collision.Scene) end function Script:Collision(entity,position,normal,speed) self:Activate(); end function Script:Activate() if (self.is_active == 0) then self.is_active = 1; self.timer = Time:GetCurrent() + self.Trigger_Delay; end end function Script:UpdateWorld() end function Script:UpdatePhysics() if (self.is_active == 1) then if (Time:GetCurrent() > self.timer) then local pos = self.entity:GetPosition(true); pos.y = pos.y + 0.1 * Time:GetSpeed(); self.entity:PhysicsSetPosition(pos.x,pos.y,pos.z,0.2); end end end Quote Link to comment Share on other sites More sharing options...
tjheldna Posted May 26, 2015 Share Posted May 26, 2015 Sorry don't have any example code at the moment but I believe you would want to attach the platform to a Slider Joint so the player moves properly with the elevator. This would be especially important if the elevator moved sideways. There may be an example of this in a demo project. http://www.leadwerks.com/werkspace/page/api-reference/_/joint/jointslider-r737 Can't see the character very well but he looks cool. Quote Link to comment Share on other sites More sharing options...
reepblue Posted May 26, 2015 Share Posted May 26, 2015 Sorry don't have any example code at the moment but I believe you would want to attach the platform to a Slider Joint so the player moves properly with the elevator. This would be especially important if the elevator moved sideways. There may be an example of this in a demo project. http://www.leadwerks.com/werkspace/page/api-reference/_/joint/jointslider-r737 Can't see the character very well but he looks cool. No. You don't want to use the sliding door script as boxes and players would weigh it down. I had the same issue in my game. You need a non-physics based object that moves. (No mass, no joints). This is my script that I used in Vectronic. Feel free to use it.: import "Scripts/Functions/ReleaseTableObjects.lua" Script.restinglocation=nil Script.move=false Script.movedistance=0 --float "Move Distance" Script.movespeed=1 --float "Move Speed" Script.startopened=false --bool "Start Opened" Script.negitive=false --bool "dev" -- Sound Script.opensoundfile=""--path "Open Sound" "Wav File (*wav):wav|Sound" Script.closesoundfile=""--path "Close Sound" "Wav File (*wav):wav|Sound" Script.loopsoundfile=""--path "Loop Sound" "Wav File (*wav):wav|Sound" Script.stopsoundfile=""--path "Stop Sound" "Wav File (*wav):wav|Sound" function Script:Start() self.restinglocation = self.entity:GetPosition() self.iy = self.restinglocation.y self.targetlocation = Vec3(self.restinglocation.x,self.restinglocation.y + self.movedistance / 100,self.restinglocation.z) if self.startopened then self.entity:SetPosition(self.targetlocation) self.opened=true end self.sound={} if self.opensoundfile~="" then self.sound.open = Sound:Load(self.opensoundfile) end if self.loopsoundfile~="" then self.sound.loop = Sound:Load(self.loopsoundfile) end if self.closesoundfile~="" then self.sound.close = Sound:Load(self.closesoundfile) end if self.stopsoundfile~="" then self.sound.stop = Sound:Load(self.stopsoundfile) end if self.sound.loop~=nil then self.loopsource = Source:Create() self.loopsource:SetSound(self.sound.loop) self.loopsource:SetLoopMode(true) self.loopsource:SetRange(50) end -- Should always use a dynamic shadow. self.entity:SetShadowMode(2) local e = self.entity:CountChildren() for n=1,e do --System:Print(n) cl = n - 1 local c = self.entity:GetChild(cl) c:SetShadowMode(2) end end function Script:UpdateWorld() if self.movedistance >= 0 then self:NormalToggle() else self:NegitiveToggle() end end function Script:NormalToggle() if self.move then if not self.opened then if self.iy < self.targetlocation.y then self.entity:SetPosition(self.restinglocation.x,self.iy,self.restinglocation.z) self.iy=self.iy + self.movespeed * Time:GetSpeed()/100 elseif self.iy >= self.targetlocation.y then self.iy = self.targetlocation.y self.move = false self.opened=true self:StopSound() self.component:CallOutputs("OnOpened") end else if self.iy > self.restinglocation.y then self.entity:SetPosition(self.restinglocation.x,self.iy,self.restinglocation.z) self.iy=self.iy - self.movespeed * Time:GetSpeed()/100 elseif self.iy <= self.restinglocation.y then self.iy = self.restinglocation.y self.move = false self.opened=false self:StopSound() self.component:CallOutputs("OnClosed") end end end end function Script:NegitiveToggle() if self.move then if not self.opened then if self.iy > self.targetlocation.y then self.entity:SetPosition(self.restinglocation.x,self.iy,self.restinglocation.z) self.iy=self.iy - self.movespeed * Time:GetSpeed()/100 elseif self.iy <= self.targetlocation.y then self.iy = self.targetlocation.y self.move = false self.opened=true self:StopSound() self.component:CallOutputs("OnOpened") end else if self.iy < self.restinglocation.y then self.entity:SetPosition(self.restinglocation.x,self.iy,self.restinglocation.z) self.iy=self.iy + self.movespeed * Time:GetSpeed()/100 elseif self.iy >= self.restinglocation.y then self.iy = self.restinglocation.y self.move = false self.opened=false self:StopSound() self.component:CallOutputs("OnClosed") end end end end function Script:StartLoopSound() if self.loopsource~=nil then self.loopsource:SetPosition(self.entity:GetPosition(true)) if self.loopsource:GetState()==Source.Stopped then self.loopsource:Play() end end end function Script:StopSound() if self.sound.stop ~= nil then self.entity:EmitSound(self.sound.stop) end if self.loopsource~=nil then self.loopsource:Stop() end end function Script:Open()--in self.opened=false if not self.opened then --if not self.move then self.move = true self:StartLoopSound() if self.sound.open then self.entity:EmitSound(self.sound.open) end self.component:CallOutputs("Open") --end end end function Script:Close()--in self.opened=true if self.opened then --if not self.move then self.move = true self:StartLoopSound() if self.sound.close then self.entity:EmitSound(self.sound.close) end self.component:CallOutputs("Close") --end end end I put the move code in UpdateWorld than UpdatePhysics because the platform goes closer back to it's original resting point better with UpdateWorld. 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Skrakle Posted May 26, 2015 Author Share Posted May 26, 2015 Thanks for the script, it does the same thing as mine when i previously tried SetPosition instead of PhysicsSetPosition. The platform movement is smoother but the character still doesn't follow it unless i keep moving on it. Seems i need to keep the character's physics updated somehow when idling and my player script is in c++ so i'm not sure how to make this work properly. Quote Link to comment Share on other sites More sharing options...
reepblue Posted May 26, 2015 Share Posted May 26, 2015 I had this issue (But it strangely went away). You can try parenting a pushing trigger upwards or add this: function Script:Collision(entity, position, normal, speed) if self.move then if entity:GetKeyValue("type") == "player" then System:Print("Entity Touching") self.currentPushForceDir = self.PushForceDir entity:SetVelocity(self.PushForceDir, true) end end end At the top of the script, add: Script.PushForceDir=Vec3(0,0,0) --Vec3 "Force Direction" Script.currentPushForceDir=Vec3(0,0,0) The goal is to keep the player moving. Experiment with self.PushForceDir on the y axis. I accidentally found this trying to push the player off of moving platforms. If the collision function is not spiting it's print, then move the pushing to a trigger volume. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Skrakle Posted May 26, 2015 Author Share Posted May 26, 2015 I managed to find a way to keep the character physics updated by sending a bogus movement and cancelling it out right after. Not sure how it would affect performance but it works perfectly. // when idling player_entity->model->SetInput(player_entity->rotation.y, 1, 0, 0, false, 1, 0.5, true); player_entity->model->SetInput(player_entity->rotation.y, 0, 0, 0, false, 1, 0.5, true); Quote Link to comment Share on other sites More sharing options...
Einlander Posted May 26, 2015 Share Posted May 26, 2015 Want to see something funny? Put something heavy on your elevator, then jump repeatedly on it, it will fall out from under you. You can test this on the fps tutorial.that comes with Leadwerks. Quote Link to comment Share on other sites More sharing options...
reepblue Posted May 26, 2015 Share Posted May 26, 2015 I guess it was something in the player code. Mine is not the stock FPSPlayer so it may be why mine worked fine. (also it's a bit harder to notice in first person.) Want to see something funny? Put something heavy on your elevator, then jump repeatedly on it, it will fall out from under you. You can test this on the fps tutorial.that comes with Leadwerks. My lua script solves that problem. The issue was updating the player while it was moving. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
CreativeOcclusion Posted May 26, 2015 Share Posted May 26, 2015 I used imported model instead of CSG...added sliding door script and have had no problems...fast and easy... Quote Link to comment Share on other sites More sharing options...
tjheldna Posted May 26, 2015 Share Posted May 26, 2015 platform movement is smoother but the character still doesn't follow it unless i keep moving on it Actually Yes that's exactly why you need to use a joint, the player wont follow the platforms position otherwise. I've created a moving platform using a slider joints and the player follows the platform where ever it goes. Another thing to take into consideration using this method is to create a custom collision type for the platform that doesn't collide with the "Scene" else it can send it off course. There are these scripts in the default MyGame Project. Objects\Physics\Platform.lua Objects\Physics\PlatformWaypoint.lua I can get you the files if you can't find them. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted May 26, 2015 Author Share Posted May 26, 2015 Actually Yes that's exactly why you need to use a joint, the player wont follow the platforms position otherwise. I've created a moving platform using a slider joints and the player follows the platform where ever it goes. Another thing to take into consideration using this method is to create a custom collision type for the platform that doesn't collide with the "Scene" else it can send it off course. There are these scripts in the default MyGame Project. Objects\Physics\Platform.lua Objects\Physics\PlatformWaypoint.lua I can get you the files if you can't find them. Found them in Scripts/Objects/Physics, i'll check it out later. Thanks! Quote Link to comment Share on other sites More sharing options...
Skrakle Posted May 26, 2015 Author Share Posted May 26, 2015 I can't figure out on how to use the platform.lua script. The problem i'm having is with: Script.target = "" --entity "Target waypoint" I can't set a target entity from the editor, it's grayed out and i can't seem to manually set one, world:FindEntity is not working, probably due to the fact that the project is c++ and not lua. 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.