QuantumPixel Posted September 27, 2016 Share Posted September 27, 2016 Greetings all, I am very new to using the Leadwerks engine and I am having trouble getting my player entity to move across the terrain I've created. The FPSPlayer.lua script works in this regard, but it was not compatible with what I needed for this project, so I had to write my own character controller script. Everything I've tried results in either the player entity falling through the terrain upon start or moving along the origin plane and passing through the terrain instead of climbing/colliding with it. I have dug through the FPSPlayer.lua script trying to find where this functionality was implemented, but I am unable to find it. Any help would be greatly appreciated. Here is my script" Script.moveSpeed = 4.0 --float "Movement Speed" Script.mouseTurn = 6.0 --float "Mouse Rotation Speed" function Script:Start() -- Create Camera self.camera = Camera:Create() self.pivot = Pivot:Create() self.camera:SetParent(self.pivot) self.camera:Move(0, 2, -2) self.camera:SetRotation(25, 0, 0) self.entity:SetKeyValue("type","player") end -- Adjust the camera orientation relative to the player function Script:UpdateCamera() self.pivot:SetPosition(self.entity:GetPosition()) self.pivot:SetRotation(self.pivot:GetRotation().x, self.pivot:GetRotation().y, 0) end function Script:UpdateWorld() local MoveX = 0 local MoveZ = 0 if window:KeyDown(Key.W) then self.entity:SetRotation(0, self.pivot:GetRotation().y, 0) MoveZ = MoveZ + 1 end if window:KeyDown(Key.S) then self.entity:SetRotation(0, self.pivot:GetRotation().y, 0) MoveZ = MoveZ - 1 end if window:KeyDown(Key.D) then MoveX = MoveX + 1 end if window:KeyDown(Key.A) then MoveX = MoveX - 1 end self.entity:Move(MoveX * self.moveSpeed / 2, 0, MoveZ * self.moveSpeed, false) if window:MouseDown(2) then if window:GetMousePosition().x > self.lastMouseX then self.pivot:Turn(0, self.mouseTurn, 0) end if window:GetMousePosition().x < self.lastMouseX then self.pivot:Turn(0, -self.mouseTurn, 0) end if window:GetMousePosition().y > self.lastMouseY then self.pivot:Turn(self.mouseTurn / 2, 0 ,0) end if window:GetMousePosition().y < self.lastMouseY then self.pivot:Turn(-self.mouseTurn / 2, 0, 0) end window:SetMousePosition(context:GetWidth() / 2, context:GetHeight() / 2) end self.lastMouseX = window:GetMousePosition().x self.lastMouseY = window:GetMousePosition().y -- Update The Camera Each Loop self:UpdateCamera() end Quote Link to comment Share on other sites More sharing options...
Roland Posted September 27, 2016 Share Posted September 27, 2016 Have you set a collision shape for the model? Model Editor/Physic Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Jazz Posted September 27, 2016 Share Posted September 27, 2016 It might be the same problem and fix as here: http://www.leadwerks.com/werkspace/topic/14757-poly-mesh-collider-not-saved-properly/ Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
QuantumPixel Posted September 27, 2016 Author Share Posted September 27, 2016 Your suggestions did fix the problem that I was having. Unfortunately, it also created new issues. Now my player entity has physics being applied to it, so it falls over and goes bouncing across the terrain if it hits a rock or uneven ground. It looks like I'm going to have to approach this from a different angle. But thanks anyway, guys. I appreciate the help. Quote Link to comment Share on other sites More sharing options...
cassius Posted September 27, 2016 Share Posted September 27, 2016 This is in c++ but does your code look something like this? //Create the player player = Pivot::Create(); player->SetPosition(0, 4, 0); player->SetMass(60); player->SetPhysicsMode(Entity::CharacterPhysics); Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
QuantumPixel Posted September 28, 2016 Author Share Posted September 28, 2016 Adding "self.entity:SetPhysicsMode(Entity.CharacterPhysics)" fixed it. Thanks! 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.