Jump to content

Crouching Behaviour


dhutchison
 Share

Recommended Posts

Thanks, but I'm still not getting the crouching behaviour to work (I am running a script outside of the editor and I am sure I am using the latest update). Here are the relevant code lines I have written:

 

controller=CreateController(1.8,0.45,0.25,45,0) -- the last value (0) is the crouch height

 

This line does the update:

 

controller:Update(camerayaw,move,strafe,jump,40,10,crouch)

 

The next lines capture the crouch key being pressed:

 

if KeyHit(KEY_C)==1 then 
if controller:IsCrouched()==1 then
crouch=0
else
crouch=1
end
end

 

Pressing the C key causes nothing to happen. I also replaced "crouch" with "1" in the controller:Update line above and still saw no crouching behaviour.

Link to comment
Share on other sites

are you moving the camera as well whenever the crouch is enabled? if you turn on the DeBugPhysics, I think you will see that it is working but you need to move the camera as well to the new crouched height.

 

here is a simple game script to use in the editor that use the crouch...

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")

--Variables
dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

--Create a player controller
controller=CreateController(1.8,0.45,0.25,45,0.8)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetPositionf(0,2,0,0)
controller:SetMass(10)

controller:SetPosition(fw.main.camera.position)
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y
controller:Move(Vec3(0,-0.9,0))
crouch = 0
cameraheight=1.8

HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
FlushKeys()
FlushMouse()

local camera = fw.main.camera
--main function
while KeyHit(KEY_ESCAPE)==0 do
movespeed=6
movesmoothing=10
jump=KeyHit(KEY_SPACE)*6.0
if controller:IsAirborne()==1 then 
	jump=0 
	movesmoothing=200
end

--Camera look
gx=Round(GraphicsWidth()/2)
gy=Round(GraphicsHeight()/2)
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())
MoveMouse(gx,gy)
camerapitch=camerapitch+dy
camerayaw=camerayaw-dx
camerapitch=math.min(camerapitch,90)
camerapitch=math.max(camerapitch,-90)
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

--Player movement
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)

if KeyHit(KEY_C)==1 then 
	if controller:IsCrouched()==1 then
		crouch=0
		cameraheight=1.8
	else
		crouch=1
		cameraheight=0.8
	end
end

--Update controller
controller:Update(camerayaw,move,strafe,jump,40,10,crouch)

fw:Update()

--Position camera
camera:SetPositionf(controller.position.x,controller.position.y+cameraheight,controller.position.z,1)

fw:Render()

Flip(0)
end

controller:Free()
ShowMouse()

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

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...