Jump to content

Crouching collision issue.


lxFirebal69xl
 Share

Recommended Posts

I'm having an issue with crouching in my game that doesn't allow the player to climb over certain objects.

 

Example:

post-13811-0-71476200-1481519310_thumb.jpg

 

 

The player can't walk over that if he's crouched, but can walk over it just fine while not crouched.

The code as it is allows me to crouch under an obstacle, like vents for example, but I find it funny that I'm having the opposite issue.

 

Here's my crouch script, or the parts that matter.

 

Script.crouched = false
Script.crouchheight = 1.2

 

		    -- 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 = 0
 if (self:IsCrouched()) then playerTempHeight = self.crouchHeight + playerPos.y
 else playerTempHeight = self.playerHeight + playerPos.y
 end
 --playerTempHeight = ((self:IsCrouched() == true) and crouchHeight or playerHeight)
 newCameraPos = Vec3(playerPos.x, newCameraPos.y ,playerPos.z)
--With smoothing
--CROUCH BEGIN
local target_height
--determine the height of the camera
if self.crouched then
target_height = self.crouchheight
else
target_height = self.eyeheight
end
--With smoothing
--calculate the new camera position
if newCameraPos.y<playerPos.y + target_height then
newCameraPos.y = Math:Curve(playerPos.y + target_height, newCameraPos.y, self.camSmoothing)
else
newCameraPos.y = playerPos.y + target_height
end
--CROUCH END

 

Any clues as to how I could fix this issue?

Link to comment
Share on other sites

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.

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.

 Share

×
×
  • Create New...