Tomas Posted January 15, 2017 Share Posted January 15, 2017 Hi, my entity has a mass of 10 and im trying to move it slow. I use (...if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,false) end) but entity moves too fast. Reducing force less than 10 will make entity immovable. How i can reduce the speed of entity? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 15, 2017 Share Posted January 15, 2017 Are you adding the force in update world or in update physics? In update world you need tot multiplayer with time:getspeed() Quote Link to comment Share on other sites More sharing options...
Genebris Posted January 15, 2017 Share Posted January 15, 2017 Maybe you want to use SetVelocity? Or you could reduce friction to allow smaller forces. Quote Link to comment Share on other sites More sharing options...
Tomas Posted January 15, 2017 Author Share Posted January 15, 2017 Im adding in update physics. I tried friction but cant see any difference between 0 and 1. Tried different values. How i can add velocity? Can you give me example, im not sure how to use it...? Sorry for being newbish... Quote Link to comment Share on other sites More sharing options...
Genebris Posted January 15, 2017 Share Posted January 15, 2017 http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetvelocity-r822 Quote Link to comment Share on other sites More sharing options...
Tomas Posted January 15, 2017 Author Share Posted January 15, 2017 This is my code. Entity is not moving at all even with friction 0. Entity has collision box and shape box. Script.camPos=Vec3() Script.entPos=Vec3() Script.camRotation=Vec3() Script.mouseSensitivity = 15 Script.mouseDifference=Vec2() Script.mouseOld=Vec2() Script.currentMousePos=Vec2() Script.mousepos=Vec2(0,0) function Script:Start() local window = Window:GetCurrent() local context = Context:GetCurrent() self.camera = Camera:Create() self:UpdateCamera() self.entity:SetFriction(1,1) end function Script:UpdateCamera() local context = Context:GetCurrent() local window = Window:GetCurrent() self.currentMousePos = window:GetMousePosition() window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2)) self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) self.mouseDifference.x = Math:Curve(self.currentMousePos.x - Math:Round(context:GetWidth()/2),self.mouseDifference.x,3) self.mouseDifference.y = Math:Curve(self.currentMousePos.y - Math:Round(context:GetHeight()/2),self.mouseDifference.y,3) self.camRotation.x = Math:Clamp(self.camRotation.x + self.mouseDifference.y / self.mouseSensitivity,-90,90) self.camRotation.y = self.camRotation.y + (self.mouseDifference.x / self.mouseSensitivity) self.camera:SetRotation(self.camRotation) self.entPos=self.entity:GetPosition() self.camera:SetPosition(self.entPos.x,self.entPos.y+1.8,self.entPos.z) self.entity:SetRotation(0,self.camRotation.y,0) end function Script:UpdateWorld() self:UpdateCamera() end function Script:UpdatePhysics() --Get the game window local window = Window:GetCurrent() self.entity:SetFriction(1,1) if window:KeyDown(Key.W) then self.entity:SetVelocity(0,0,10,false) end --if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,false) end --if window:KeyDown(Key.A) then self.entity:AddForce(-speed,0,0,false) end --if window:KeyDown(Key.D) then self.entity:AddForce(speed,0,0,false) end --if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-speed,false) end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 15, 2017 Share Posted January 15, 2017 Don't know. Your code worked fine for me. Setting the friction to 0 just made the box slide for a little after the user input was no more. I can set the velocity.z down to 1 and it still moves. Also, using the AddForce.z at 10 works as well when the friction is set to 0. If the friction is set to 1 then just increase the value to overcome the box's mass and gravity. Speaking of which, if the numbers above are not working for you what is your scene's gravity set to? The default is 25. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Tomas Posted January 16, 2017 Author Share Posted January 16, 2017 Well,i finally got the answer to my problem. Its here http://www.leadwerks.com/werkspace/page/documentation/_/entity/entitysetinput-r706 . Thanks everyone for help. Some physics functions dont work if character controller physics mode is used, but with that function i have what i need. Thanks 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.