|
I have put together a simple FPS game, but I just can't get my character to crouch. I've searched it up and have seen people shorten the Character Controller, but what I would like is to have the character controller shorten, and the camera as well. This way, the character can squeeze into places like vents, holes, or whatever. I've seen Controller.height = 0.5, but I also would like the camera to move down with it. Thanks in advance :D
(comments are locked)
|
|
This is what I do, the function crouch lowers the character controller height & collider and sets crouching to true. crouchDeltaHeight is my variable for the height change when crouching. (All of this would be in the FPSWalker default script).
And then in update the camera lowers to crouch height if crouching or returns to normal otherwise (it's in update to make it look smooth).
This is the code to stop crouching and return to normal:
And here's what I have in update to trigger it: Again, another brilliant Answer from DastardlyBanana :D Thanks very much
Jul 08 '10 at 06:43 PM
Flipbee9
I keep getting errors about crouchDeltaHeight, standardCamHeight and etc. I'm guessing I'm supposed to set up the variables and so I did so. But about the BoxCollider, I'm using a character controller instead of a box collider
Jul 08 '10 at 07:15 PM
Flipbee9
Well then you can probably just cut that out.
Jul 08 '10 at 07:48 PM
Jason_DB
how do i make this work
Aug 12 '10 at 08:51 PM
josh
(comments are locked)
|
|
so how do i put in that code? sorry i just started unity yesterday and i have a good fps going now
(comments are locked)
|
|
My suggestion would be having five variables, for the hieght and camera position before and after crouching and a variable that ays if you are crouching. Have the camera position be relative, so that it is always added to the characters own position. If your weapons are a child of your camera then you will see them move down as well. This may be an issue with graphics, as if you are using a mesh for the character you will have to create an entire motion sequence seperate from the original and have them programmed individualy (Animation Programing can be a pain in FPS) and afterwards should you want a death scene the rigidbody formed would have to be altered for a 'crouch death'. Lastly you would be forced to decide how your crouching affects your jumping, whether you can jump when crouched, if so can you jump as high, and that would involve delving into the fps character made by unity (I am presuming you are using it.) which is a difficult process.
(comments are locked)
|
|
Fore anyone trying to use the FPS controller:
(comments are locked)
|
|
I don't know if this is the best solution but I was thinking as long as you had the camera parented to the capsule you are using as your character you could just make an animation that scales the capsule on the y-axis. you could do that but I've learned through sad experience that when you do that an you're holding a gun or other mesh it gets scrunched too.
Oct 06 '10 at 06:36 PM
Jordan Miller 2
however that can be remedied by replacing the mesh every time you crouch or stand up.
Oct 06 '10 at 06:37 PM
Jordan Miller 2
(comments are locked)
|
1 2 next page »
