Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hugemaggot · Nov 22, 2010 at 07:06 PM · fpscrouch

how to make an fps character crouch

ive been working on a fps game for the past few days but I don't know how to make my character crouch please can you help me. by the way I'm quite new to unity so please don't make the answer to complicated.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Nov 22, 2010 at 07:19 PM 0
Share

Okay, Have you made your character? Or are you still using the default capsule as the graphic?

avatar image hugemaggot · Nov 23, 2010 at 07:02 PM 0
Share

i am currently using the default capsule because i dont know how to make a character.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by skovacs1 · Nov 22, 2010 at 08:08 PM

There's a whole bunch to consider as far as what else your character is doing (can you jump when crouched? Is it different than jumping otherwise? How is it different? Does your movement speed change when crouching? etc.). You don't include any information about your setup such as your camera setup, your character setup, whether you are using a CharacterController, do you have animations, etc. The simple approach (while making some broad assumptions about what you are doing because you don't describe at all) is something like:

var crouching : boolean = false; var altHeightChange : float = 3.0f; private var controller : CharacterController;

function Start() { controller = GetComponent(CharacterController); }

function Update() { if(controller && Input.GetButtonUp("Crouch")) { //Crouch on/off crouching = !crouching; if(crouching) { controller.center.y -= altHeightChange 0.5f; controller.height -= altHeightChange; //move your camera down by altHeightChange animation.CrossFade("crouch"); } else { controller.center.y += altHeightChange 0.5f; controller.height += altHeightChange //move your camera up by altHeightChange animation.CrossFade("stand"); } } }

If you wanted crouch only when the key is held down, something like this:

var altHeightChange : float = 3.0f; private var controller : CharacterController;

function Start() { controller = GetComponent(CharacterController); }

function Update() { if(controller) { if(Input.GetButtonDown("Crouch")) { //Crouch on controller.center.y -= altHeightChange 0.5f; controller.height -= altHeightChange; //move your camera down by altHeightChange animation.CrossFade("crouch"); } if(Input.GetButtonUp("Crouch")) { //Crouch off controller.center.y += altHeightChange 0.5f; controller.height += altHeightChange //move your camera up by altHeightChange animation.CrossFade("stand"); } } }

If you have more states than crouching or standing, such as prone or jumping, etc. you might consider using and enum for your state.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hugemaggot · Nov 28, 2010 at 12:33 PM 0
Share

thankyou for helping me

avatar image oinkoinkflapflap · Feb 08, 2011 at 08:45 AM 0
Share

brill script but, do you know how i can find how to make the camera down 2... thanks :D great script though

avatar image Borzi · Apr 23, 2013 at 06:52 PM 0
Share

I officially love you for this script kind sir, if you happen to be in Düsseldorf, drinks on me!

avatar image
0
Best Answer

Answer by oliver-jones · Nov 23, 2010 at 04:16 AM

You might want to take a look at this post too:

http://answers.unity3d.com/questions/14803/how-to-make-the-fps-character-crouch

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How to Make the FPS Character Controller RUN and CROUCH 0 Answers

How To Make The FPS Character Crouch 8 Answers

force player to crouch when under an object with collisio 2 Answers

FPS Character controller crouch sneak 0 Answers

Make character either crouch or go prone depending on how long a button is held? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges