Haydenmango Posted November 10, 2014 Share Posted November 10, 2014 Lots of people ask me to help them get crouching to work so I edited the FPSplayer.lua slightly so that it will work with crouching. I thought I would post a link to it here since a lot of people have trouble figuring this out. https://www.dropbox.com/s/rbh1iof5qubss78/Edited%20FPSplayer.lua?dl=0 3 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 10, 2014 Share Posted November 10, 2014 Thats great Hayden. Something i just figured wasnt quite ready even if its just moving the camera down to a lower level. How might we assign a specific key for this? I think its control in the script when i was looking at it. Id rather it be "C". Ill try to figure that out on my own unless you pass along a secret to us all. BTW, GREAT contributions like this will make the community stronger! lines 592-595 appears to be for setting the crouch button so- -- Check for crouching if window:KeyHit(Key.ControlKey) then self.crouched = not self.crouched end could be made into -- Check for crouching if window:KeyHit(Key.C) then self.crouched = not self.crouched end Then it appears as if lines 597 - 618 are the crouch function.? Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Haydenmango Posted November 10, 2014 Author Share Posted November 10, 2014 No Problem, I am glad to help! lines 592-595 appears to be for setting the crouch button so--- Check for crouching if window:KeyHit(Key.ControlKey) then self.crouched = not self.crouched end could be made into -- Check for crouching if window:KeyHit(Key.C) then self.crouched = not self.crouched end Yep, that is where you can change the Key that activates/deactivates Crouching. Thanks for pointing that out I am sure others will find that useful. Then it appears as if lines 597 - 618 are the crouch function.? Lines 605-610 are the lines that actually make the camera move to your crouch height and I also changed line 599 from - self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true) to - self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , self.crouched, 1.0, 0.5, true) to activate the Character Controllers crouching function. 1 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 11, 2014 Share Posted November 11, 2014 Got myself an error. Nothing new for me but I got attempt to perform arithemetic on field "crouchedheight" (a nil value) line 646 if it needs to be broken, let me play with it. I copied and pasted the new section into my FPSPlayer.lua file as there are changes made to mine already. Here is the new part pasted. -- Check for crouching if window:KeyHit(Key.C) then self.crouched = not self.crouched end --With smoothing --Position camera at correct height and playerPosition self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , self.crouched, 1.0, 0.5, true) local playerPos = self.entity:GetPosition() local newCameraPos = self.camera:GetPosition() --local playerTempHeight = ((self:IsCrouched() == 1) and crouchHeight or playerHeight) newCameraPos = Vec3(playerPos.x, newCameraPos.y ,playerPos.z) if self.crouched==true then if newCameraPos.y<playerPos.y + self.crouchedheight then newCameraPos.y = Math:Curve(playerPos.y + self.crouchedheight, newCameraPos.y, self.camSmoothing) else newCameraPos.y = playerPos.y + self.crouchedheight end elseif newCameraPos.y<playerPos.y + self.eyeheight then newCameraPos.y = Math:Curve(playerPos.y + self.eyeheight, newCameraPos.y, self.camSmoothing) else newCameraPos.y = playerPos.y + self.eyeheight end self.camera:SetPosition(newCameraPos) end Here is my entire file if interested in looking at it.FPSPlayer.lua Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Haydenmango Posted November 11, 2014 Author Share Posted November 11, 2014 Well line 646 is local pickUpX = math.floor((context:GetWidth() - self.image.hand:GetWidth()))/2 for me so that doesn't make any sense. Have you edited the script at all? Also if you go to your characters Script tab is the Crouch Height value equal to a number? Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 11, 2014 Share Posted November 11, 2014 OK, I forgot to add in the top section addition of the file. NOW, it throws an error about: fpsplayer.lua" : 153 : attempt to index field 'camera' (a nil value) Shouldnt have anythign to do with this right? Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 11, 2014 Share Posted November 11, 2014 I think its the changes from the weapon pick up script since I added a line that stops the creation of the camera since I set one in the scene. Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Haydenmango Posted November 11, 2014 Author Share Posted November 11, 2014 Ok, just looked over your script and it looks like you just need to change - Script.Camera=nil to Script.camera=nil Capitalization can change everything! edit-- Also you will need Script.crouched=false Script.crouchedheight=.9 --float "Crouch Height" at the top of your script for crouching. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 11, 2014 Share Posted November 11, 2014 back to the error on attempt to index field 'camera' (a nil value) Attached the edited file. for me, the line in question is 154 self.camera:SetFOV(70) FPSPlayer.lua Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Haydenmango Posted November 11, 2014 Author Share Posted November 11, 2014 Did you place your camera into the Camera box under your Characters Script Tab? edit---waiiitttt I found the problem, line 152-153 change --self.camera = Camera:Create() self.camera = self.Camera to self.camera=Camera:Create() Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Imchasinyou Posted November 11, 2014 Share Posted November 11, 2014 Yep, sure did. . . . I even removed it and replaced it. Sent you a PM and a steam invite Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
Haydenmango Posted November 11, 2014 Author Share Posted November 11, 2014 I updated the script so you can choose between clicking ctrl to crouch or holding ctrl to crouch. https://www.dropbox.com/s/rbh1iof5qubss78/Edited%20FPSplayer.lua?dl=0 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding 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.