Pfctink Posted February 27, 2016 Share Posted February 27, 2016 I have been messing around with a script in the FPSplayer, trying to get crouching to work is hard. How would I go about being able to crouch under objects? I have my script here: http://pastebin.com/wxSsy1hP Quote Link to comment Share on other sites More sharing options...
SpEcIeS Posted February 27, 2016 Share Posted February 27, 2016 Maybe this will help you out? http://www.leadwerks.com/werkspace/topic/12805-basic-sneaking-tutorial/page__hl__crouch Quote SpEcIeS Link to comment Share on other sites More sharing options...
Pfctink Posted February 27, 2016 Author Share Posted February 27, 2016 Script.crouch does not work. Quote Link to comment Share on other sites More sharing options...
Pfctink Posted February 27, 2016 Author Share Posted February 27, 2016 Seriously, I have the crouch "working", it's just I can't go under objects. Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 28, 2016 Share Posted February 28, 2016 Seriously, I have the crouch "working", it's just I can't go under objects. How low are the objects that you are trying to crouch under? If its lower than 0.8 or 0.9 meters then you will not be able. 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...
Brutile Posted February 28, 2016 Share Posted February 28, 2016 You need to set the input for crouch. See below. I'm not sure why it wasn't included in the tutorial. self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , self.crouched, 1.0, 0.5, true) 2 Quote Link to comment Share on other sites More sharing options...
SpEcIeS Posted February 28, 2016 Share Posted February 28, 2016 Since I had not tackled this yet, I decided to this morning. ( Not adding the Peek, but only the crouch option) Brutile method seems to let the player crouch to pass below surfaces previously not able. Quote SpEcIeS Link to comment Share on other sites More sharing options...
Pfctink Posted February 28, 2016 Author Share Posted February 28, 2016 Well, I have the line set in, but it's still not working. I can crouch, but I'm not able to go under any objects. Quote Link to comment Share on other sites More sharing options...
SpEcIeS Posted February 28, 2016 Share Posted February 28, 2016 Replaced the false with self.crouched in the UpdatePhysics function? If so, maybe it is what macklebee was saying about the height. --With smoothing --Position camera at correct height and playerPosition --self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true) self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , self.crouched, 1.0, 0.5, true) 1 Quote SpEcIeS Link to comment Share on other sites More sharing options...
macklebee Posted February 29, 2016 Share Posted February 29, 2016 The crouch height is 1.2 meters (I must have been remembering old heights typically used with LE2). What may be confusing about the crouch is that the visible debug physics body does not change size when crouch is true. Example script that shows the crouch height of 1.2 meters. Use WSAD to move and hit C to crouch: window = Window:Create("crouch height",0,0,800,600,17) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:SetRotation(40,0,0) camera:Move(0,0,-8) light = DirectionalLight:Create() light:SetRotation(35,35,0) camera:SetDebugPhysicsMode(true) ground = Model:Box(10,1,10) ground:SetPosition(0,-0.5,0) ground:SetColor(0,1,0) shape = Shape:Box(0,0,0, 0,0,0, 10,1,10) ground:SetShape(shape) shape:Release() box1 = Model:Box(1,1.2,1) box1:SetPosition(-2,0.6,-1) box2 = Model:Box(1,1.2,1) box2:SetPosition(2,0.6,-1) box3 = Model:Box(5,1,1) box3:SetPosition(0,1.7,-1) shape = Shape:PolyMesh((box1:GetSurface(0))) box1:SetShape(shape) shape = Shape:PolyMesh((box2:GetSurface(0))) box2:SetShape(shape) shape = Shape:PolyMesh((box3:GetSurface(0))) box3:SetShape(shape) shape:Release() player = Pivot:Create() visiblecapsule = Model:Cylinder(16,player) visiblecapsule:SetScale(.8,1.8,.8) visiblecapsule:SetPosition(0,.9,0) player:SetPosition(-4,0,0) player:SetMass(1) player:SetPhysicsMode(Entity.CharacterPhysics) crouch = false while window:KeyHit(Key.Escape)==false do if window:Closed() then break end move = ((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0))*4 strafe = ((window:KeyDown(Key.D)and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0))*4 jump = (window:KeyHit(Key.Space) and 1 or 0)*8 if window:KeyHit(Key.C) then crouch = not crouch end player:SetInput(0,move,strafe,jump,crouch) Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:DrawText("Crouched: "..tostring(crouch),2,2) context:SetBlendMode(Blend.Solid) context:Sync() end Also note this example shows that when crouching under something, the developer needs to prevent standing back up to prevent weird physic results from occurring - ie character slingshot across map, character pushed through the map, etc... 2 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...
Pfctink Posted February 29, 2016 Author Share Posted February 29, 2016 Now how would I be able to apply this to the FPSplayer prefab? 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.