Jump to content
AtomicHashtag

Crouching Script (lua)

Recommended Posts

Crouching on the inherent character controller physics container appears to be currently disabled. This means the cylinder used for the character does not change height. But you can still simulate the look of crouching by just setting the height of the camera to a lower position. Granted due the character cylinder not changing height at the moment, you will be unable to actually go under anything that a normal standing character cylinder cannot go under.

Share this post


Link to post

Crouching on the inherent character controller physics container appears to be currently disabled. This means the cylinder used for the character does not change height. But you can still simulate the look of crouching by just setting the height of the camera to a lower position. Granted due the character cylinder not changing height at the moment, you will be unable to actually go under anything that a normal standing character cylinder cannot go under.

 

Again, I made a character that can go under stuff. If you play Vectronic use the 0g and ghost box combo to make a ghost box float around half the player's height, they player will go under it and there is a picker test to tell the player not to get up if they are under an object...

Share this post


Link to post

To the OP, this code should work in FPSPlayer.lua (untested, put in UpdatePhysics()):

local window=Window:GetCurrent() --youi may not need this line, check to see if it already exists
if window:KeyDown(Key.Control) then
self.entity:SetInput(self.entity:GetRotation(true).y,0,0,0,false)
end
if self.entity:GetCrouched() then
self.camera:SetPosition(self.entity:GetPosition()+Vec3(0,2,0))
else
self.camera:SetPosition(self.entity:GetPosition()+Vec3(0,1,0))
end

 

Crouching is not disabled, it's just that some people, including me, wanted control over how much the character can crouch. It gets frustrating when you can only crouch to about 2/3 the total height (so vents are impossible and going prone is also impossible).

Share this post


Link to post

Previous LE3 versions would alter the character's physics cylinder height which I mistakenly assumed it meant it was disabled. The parameter for crouch in the SetInput() command provides feedback for the entity:GetCrouched() command. And yes, like I mentioned in my previous post, you can still simulate the look of being crouched by moving the camera height.

 

Also, your code above needs to toggle the crouch variable.

 

-- Check for crouching

if window:KeyHit(Key.C) then

crouched = not crouched

end

...

...

self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , crouched, 1.0, 0.5, true)

...

 

if self.entity:GetCrouched() then

self.camera:SetPosition(self.entity:GetPosition()+Vec3(0,1,0))

else

self.camera:SetPosition(self.entity:GetPosition()+Vec3(0,2,0))

end

 

Note that you also had the y-value swapped for crouched/not crouched.

Share this post


Link to post

Well, I know crouch works because I've been using it in my project right now (I used it yesterday) to get under smaller regions. I haven't used GetCrouched() to be honest, so maybe that's broken, but the SetInput() works for me (I'm on the beta).

 

Every time you call SetInput(), the crouch reverts back to true by default unless you specify otherwise. Maybe this is what is causing it to not work properly on your end?

Share this post


Link to post

Yes you are right - it appears that only the drawing of the physics container is not being modified. Once I saw that I assumed that it was disabled and apparently Josh is under that impression as well since he basically stated as such last night. And GetCrouched() is not broken but you have to use the parameter in the SetInput() command for it to work.

 

Every time you call SetInput(), the crouch reverts back to true by default unless you specify otherwise. Maybe this is what is causing it to not work properly on your end?

 

That is why I said you have to toggle the variable like I showed above. If you want it revert back to 'not crouched' automatically then simply use KeyDown instead of KeyHit.

-- Check for crouching

crouched = false

if window:KeyDown(Key.C) then

crouched = true

end

...

...

self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , crouched, 1.0, 0.5, true)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...