├── .github └── ISSUE_TEMPLATE │ └── bug_report.yml ├── LICENSE ├── PlayerMovement.cs ├── PlayerSetup.cs ├── README.md └── readmeAssets ├── 1.PNG ├── 2.PNG ├── 3.PNG ├── 4.PNG ├── 5.PNG ├── coyoteTime.gif ├── crouching.gif ├── groundLayer.gif └── varJumpHeight.gif /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | 3 | title: I have found a bug!!! 4 | 5 | description: Report bugs so this controller can be improved 6 | 7 | labels: Bug 8 | 9 | body: 10 | 11 | - type: input 12 | attributes: 13 | label: What Unity version are you using? 14 | description: Just the year and the first number afterwards 15 | placeholder: "Example: 2021.3" 16 | validations: 17 | required: true 18 | 19 | - type: textarea 20 | attributes: 21 | label: Expected behavior vs actual behavior 22 | render: text 23 | placeholder: | 24 | What did you expect and what actually happened? (Optional) 25 | validations: 26 | required: true 27 | 28 | - type: textarea 29 | attributes: 30 | label: General steps to reproduce 31 | description: Doesn't have to be too specific, just enough to reproduce 32 | render: text 33 | placeholder: | 34 | Download and import into project 35 | then... 36 | validations: 37 | required: true 38 | 39 | - type: textarea 40 | attributes: 41 | label: Any changes made to the base code? 42 | description: List changes made to the code. If none leave blank 43 | render: text 44 | placeholder: "blank" 45 | validations: 46 | required: false 47 | 48 | 49 | - type: textarea 50 | attributes: 51 | label: Other details 52 | render: text 53 | placeholder: | 54 | Note anything else you can provide regarding the issue you're running into. 55 | validations: 56 | required: false 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Bonehead 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PlayerMovement.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // By B0N3head 4 | // All yours, use this script however you see fit, feel free to give credit if you want 5 | [AddComponentMenu("Player Movement and Camera Controller")] 6 | public class PlayerMovement : MonoBehaviour 7 | { 8 | [Header("Camera Settings")] 9 | 10 | [Tooltip("Lock the cursor to the game screen on play")] 11 | public bool lockCursor = true; 12 | [Tooltip("Clamp the camera angle (Stop the camera form \"snapping its neck\")")] 13 | public Vector2 clampInDegrees = new Vector2(360f, 180f); 14 | [Tooltip("The mouse sensitivity, both x and y")] 15 | public Vector2 sensitivity = new Vector2(2f, 2f); 16 | [Tooltip("Smoothing of the mouse movement (Try with and without)")] 17 | public Vector2 smoothing = new Vector2(1.5f, 1.5f); 18 | [Tooltip("Needs to be the same name as your main cam")] 19 | public string cameraName = "Camera"; 20 | 21 | //---------------------------------------------------- 22 | [Space] 23 | [Header("Movement Settings")] 24 | 25 | [Tooltip("Max walk speed")] 26 | public float walkMoveSpeed = 7.5f; 27 | [Tooltip("Max sprint speed")] 28 | public float sprintMoveSpeed = 11f; 29 | [Tooltip("Max jump speed")] 30 | public float jumpMoveSpeed = 6f; 31 | [Tooltip("Max crouch speed")] 32 | public float crouchMoveSpeed = 4f; 33 | 34 | //---------------------------------------------------- 35 | [Header("Crouch Settings")] 36 | 37 | [Tooltip("How long it takes to crouch")] 38 | public float crouchDownSpeed = 0.2f; 39 | [Tooltip("How tall the character is when they crouch")] 40 | public float crouchHeight = 0.68f; //change for how large you want when crouching 41 | [Tooltip("How tall the character is when they stand")] 42 | public float standingHeight = 1f; 43 | [Tooltip("Lerp between crouching and standing")] 44 | public bool smoothCrouch = true; 45 | [Tooltip("Can you crouch while in the air")] 46 | public bool jumpCrouching = true; 47 | 48 | //---------------------------------------------------- 49 | [Header("Jump Settings")] 50 | 51 | [Tooltip("Initial jump force")] 52 | public float jumpForce = 110f; 53 | [Tooltip("Continuous jump force")] 54 | public float jumpAccel = 10f; 55 | [Tooltip("Max jump up time")] 56 | public float jumpTime = 0.4f; 57 | [Tooltip("How long you have to jump after leaving a ledge (seconds)")] 58 | public float coyoteTime = 0.2f; 59 | [Tooltip("How long I should buffer your jump input for (seconds)")] 60 | public float jumpBuffer = 0.1f; 61 | [Tooltip("How long do I have to wait before I can jump again")] 62 | public float jumpCooldown = 0.6f; 63 | [Tooltip("Fall quicker")] 64 | public float extraGravity = 0.1f; 65 | [Tooltip("The tag that will be considered the ground")] 66 | public string groundTag = "Ground"; 67 | 68 | //---------------------------------------------------- 69 | [Space] 70 | [Header("Keyboard Settings")] 71 | 72 | [Tooltip("The key used to jump")] 73 | public KeyCode jump = KeyCode.Space; 74 | [Tooltip("The key used to sprint")] 75 | public KeyCode sprint = KeyCode.LeftShift; 76 | [Tooltip("The key used to crouch")] 77 | public KeyCode crouch = KeyCode.Z; 78 | [Tooltip("The key used to toggle the cursor")] 79 | public KeyCode lockToggle = KeyCode.Q; 80 | 81 | //---------------------------------------------------- 82 | [Space] 83 | [Header("Debug Info")] 84 | 85 | [Tooltip("Are we on the ground?")] 86 | public bool areWeGrounded = true; 87 | [Tooltip("Are we crouching?")] 88 | public bool areWeCrouching = false; 89 | [Tooltip("The current speed I should be moving at")] 90 | public float currentSpeed; 91 | 92 | //---------------------------------------------------- 93 | // Reference vars (These are the vars used in calculations, they don't need to be set by the user) 94 | private Rigidbody rb; 95 | private GameObject cam; 96 | Vector3 input = new Vector3(); 97 | Vector2 _mouseAbsolute, _smoothMouse, targetDirection, targetCharacterDirection; 98 | private float coyoteTimeCounter, jumpBufferCounter, startJumpTime, endJumpTime; 99 | private bool wantingToJump = false, wantingToCrouch = false, wantingToSprint = false, jumpCooldownOver = true; 100 | 101 | void Awake() 102 | { 103 | // Just set rb to the rigidbody of the gameobject containing this script 104 | rb = gameObject.GetComponent(); 105 | // Try find our camera amongst the child objects 106 | cam = gameObject.transform.Find(cameraName).gameObject; 107 | // Set the currentSpeed to walking as no keys should be pressed yet 108 | currentSpeed = walkMoveSpeed; 109 | 110 | // Set target direction to the camera's initial orientation. 111 | targetDirection = transform.localRotation.eulerAngles; 112 | // Set target direction for the character body to its inital state. 113 | targetCharacterDirection = transform.localRotation.eulerAngles; 114 | } 115 | 116 | private void Update() 117 | { 118 | // Update the camera pos 119 | cameraUpdate(); 120 | 121 | // Move all input to Update(), then use given input on FixedUpdate() 122 | 123 | // WSAD movement 124 | input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); 125 | // Jump key 126 | wantingToJump = Input.GetKey(jump); 127 | // Crouch key 128 | wantingToCrouch = Input.GetKey(crouch); 129 | // Sprint key 130 | wantingToSprint = Input.GetKey(sprint); 131 | 132 | // Mouse lock toggle (KeyDown only fires once) 133 | if (Input.GetKeyDown(lockToggle)) 134 | lockCursor = !lockCursor; 135 | } 136 | 137 | public void cameraUpdate() 138 | { 139 | // Allow the script to clamp based on a desired target value. 140 | var targetOrientation = Quaternion.Euler(targetDirection); 141 | var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection); 142 | 143 | // Get raw mouse input for a cleaner reading on more sensitive mice. 144 | var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); 145 | 146 | // Scale input against the sensitivity setting and multiply that against the smoothing value. 147 | mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y)); 148 | 149 | // Interpolate mouse movement over time to apply smoothing delta. 150 | _smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x); 151 | _smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y); 152 | 153 | // Find the absolute mouse movement value from point zero. 154 | _mouseAbsolute += _smoothMouse; 155 | 156 | // Clamp and apply the local x value first, so as not to be affected by world transforms. 157 | if (clampInDegrees.x < 360) 158 | _mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f); 159 | 160 | // Then clamp and apply the global y value. 161 | if (clampInDegrees.y < 360) 162 | _mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f); 163 | 164 | cam.transform.localRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right) * targetOrientation; 165 | 166 | var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, Vector3.up); 167 | transform.localRotation = yRotation * targetCharacterOrientation; 168 | } 169 | 170 | void FixedUpdate() 171 | { 172 | // Lock cursor handling 173 | if (lockCursor) 174 | Cursor.lockState = CursorLockMode.Locked; 175 | else 176 | Cursor.lockState = CursorLockMode.None; 177 | 178 | // Double check if we are on the ground or not (Changes current speed if true) 179 | // --- QUICK EXPLINATION --- 180 | // transform.position.y - transform.localScale.y + 0.1f 181 | // This puts the start of the ray 0.1f above the bottom of the player 182 | // We then shoot a ray 0.15f down, this exists the player with 0.5f to hit objects 183 | // Removing this +- of 0.1f and having it shoot directly under the player can skip the ground as sometimes the capsules bottom clips through the ground 184 | if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y - transform.localScale.y + 0.1f, transform.position.z), Vector3.down, 0.15f)) 185 | handleHitGround(); 186 | 187 | // Sprinting 188 | if (wantingToSprint && areWeGrounded && !areWeCrouching) 189 | currentSpeed = sprintMoveSpeed; 190 | else if (!areWeCrouching && areWeGrounded) 191 | currentSpeed = walkMoveSpeed; 192 | 193 | // Crouching 194 | // Can be simplified to Crouch((wantingToCrouch && jumpCrouching)); though the bellow is more readable 195 | if (wantingToCrouch && jumpCrouching) 196 | Crouch(true); 197 | else 198 | Crouch(false); 199 | 200 | // Coyote timer (When the player leaves the ground, start counting down from the set value coyoteTime) 201 | // This allows players to jump late. After they have left 202 | if (areWeGrounded) 203 | coyoteTimeCounter = coyoteTime; 204 | else 205 | coyoteTimeCounter -= Time.deltaTime; 206 | 207 | // Jump buffer timer (When the player leaves the ground, start counting down from the set value jumpBuffer) 208 | // This will "buffer" the input and allow for early space presses to be valid and no longer ignored 209 | if (wantingToJump) 210 | jumpBufferCounter = jumpBuffer; 211 | else 212 | jumpBufferCounter -= Time.deltaTime; 213 | 214 | // If the coyote timer has not run out and our jump buffer has not run out and we our cool down (canJump) is now over 215 | if (coyoteTimeCounter > 0f && jumpBufferCounter > 0f && jumpCooldownOver) 216 | { 217 | rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z); 218 | rb.AddForce(transform.up * jumpForce, ForceMode.Impulse); 219 | 220 | jumpCooldownOver = false; 221 | areWeGrounded = false; 222 | jumpBufferCounter = 0f; 223 | currentSpeed = jumpMoveSpeed; 224 | endJumpTime = Time.time + jumpTime; 225 | 226 | // Wait jumpCooldown (1f = 1 second) then run the jumpCoolDownCountdown() void 227 | Invoke(nameof(jumpCoolDownCountdown), jumpCooldown); 228 | } 229 | else if (wantingToJump && !areWeGrounded && endJumpTime > Time.time) 230 | { 231 | // Hold down space for a further jump (until the timer runs out) 232 | rb.AddForce(Vector3.up * jumpAccel, ForceMode.Acceleration); 233 | } 234 | 235 | // WSAD movement 236 | input = input.normalized; 237 | Vector3 forwardVel = transform.forward * currentSpeed * input.z; 238 | Vector3 horizontalVel = transform.right * currentSpeed * input.x; 239 | rb.velocity = horizontalVel + forwardVel + new Vector3(0, rb.velocity.y, 0); 240 | 241 | //Extra gravity for more nicer jumping 242 | rb.AddForce(new Vector3(0, -extraGravity, 0), ForceMode.Impulse); 243 | } 244 | 245 | private void jumpCoolDownCountdown() 246 | { 247 | jumpCooldownOver = true; 248 | } 249 | 250 | // Crouch handling 251 | private void Crouch(bool crouch) 252 | { 253 | areWeCrouching = crouch; 254 | 255 | if (crouch) 256 | { 257 | // If the player is crouching 258 | currentSpeed = crouchMoveSpeed; 259 | 260 | if (smoothCrouch) 261 | { 262 | transform.localScale = new Vector3(transform.localScale.x, Mathf.Lerp(transform.localScale.y, crouchHeight, crouchDownSpeed), transform.localScale.z); 263 | transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, transform.position.y - crouchHeight, transform.position.z), crouchDownSpeed); 264 | } 265 | else if (transform.localScale != new Vector3(transform.localScale.x, crouchHeight, transform.localScale.z)) 266 | { 267 | transform.localScale = new Vector3(transform.localScale.x, crouchHeight, transform.localScale.z); 268 | transform.position = new Vector3(transform.position.x, transform.position.y - crouchHeight / 2, transform.position.z); 269 | } 270 | } 271 | else 272 | { 273 | // If the player is standing 274 | if (smoothCrouch) 275 | { 276 | transform.localScale = new Vector3(transform.localScale.x, Mathf.Lerp(transform.localScale.y, standingHeight, crouchDownSpeed), transform.localScale.z); 277 | transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, transform.position.y - standingHeight / 2, transform.position.z), crouchDownSpeed); 278 | } 279 | else if (transform.localScale != new Vector3(transform.localScale.x, standingHeight, transform.localScale.z)) 280 | { 281 | transform.localScale = new Vector3(transform.localScale.x, standingHeight, transform.localScale.z); 282 | transform.position = new Vector3(transform.position.x, transform.position.y + standingHeight / 2, transform.position.z); 283 | } 284 | } 285 | } 286 | 287 | // Ground check 288 | //****** make sure whatever you want to be the ground in your game matches the tag set in the script 289 | private void OnCollisionEnter(Collision other) 290 | { 291 | if (other.gameObject.tag == groundTag) 292 | handleHitGround(); 293 | } 294 | 295 | // This is separated in its own void as this code needs to be run on two separate occasions, saves copy pasting code 296 | // Just double checking if we are crouching and setting the speed accordingly 297 | public void handleHitGround() 298 | { 299 | if (areWeCrouching) 300 | currentSpeed = crouchMoveSpeed; 301 | else 302 | currentSpeed = walkMoveSpeed; 303 | 304 | areWeGrounded = true; 305 | } 306 | 307 | // Dw about understanding this, it's just the code for setting up the player character 308 | public void setupCharacter() 309 | { 310 | gameObject.tag = "Player"; 311 | if (!gameObject.GetComponent()) 312 | { 313 | Rigidbody rb = gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody; 314 | rb.mass = 10; 315 | } 316 | else Debug.Log("Rigidbody already exists"); 317 | 318 | if (!gameObject.transform.Find("Camera")) 319 | { 320 | Vector3 old = transform.position; 321 | gameObject.transform.position = new Vector3(0, -0.8f, 0); 322 | GameObject go = new GameObject("Camera"); 323 | go.AddComponent(); 324 | go.AddComponent(); 325 | go.transform.rotation = new Quaternion(0, 0, 0, 0); 326 | go.transform.localScale = new Vector3(1, 1, 1); 327 | go.transform.parent = transform; 328 | gameObject.transform.position = old; 329 | Debug.Log("Camera created"); 330 | } 331 | else Debug.Log("Camera already exists"); 332 | } 333 | } -------------------------------------------------------------------------------- /PlayerSetup.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | // By B0N3head 5 | 6 | // This script, although readable was not created out to be super readable for beginners. 7 | // Its just for setup and is not used during gameplay 8 | [CustomEditor(typeof(PlayerMovement))] 9 | public class PlayerSetup : Editor 10 | { 11 | string dialogTitle = "Player Movement Setup v1.1", dialogYes = "Yeah", dialogNo = "No thanks"; 12 | 13 | public override void OnInspectorGUI() 14 | { 15 | DrawDefaultInspector(); 16 | PlayerMovement pmvmt = (PlayerMovement)target; 17 | GUILayout.Space(10); 18 | if (GUILayout.Button("Setup Player & World")) 19 | { 20 | if (EditorUtility.DisplayDialog( 21 | dialogTitle, 22 | "Would you like me to set custom world physics for you?\n\n" + 23 | "This changes the gravity\n" + 24 | "If this is a pre-existing project please use caution, it will change how anything using physics moves", 25 | dialogYes, 26 | dialogNo 27 | )) 28 | { 29 | Physics.gravity = new Vector3(0, -19F, 0); 30 | Debug.Log("Physics set"); 31 | } 32 | 33 | if (EditorUtility.DisplayDialog( 34 | dialogTitle, 35 | "Would you like me to create a \"Ground\" tag for you?", 36 | dialogYes, 37 | dialogNo 38 | )) 39 | { 40 | createTag("Ground"); 41 | } 42 | 43 | pmvmt.setupCharacter(); 44 | 45 | EditorUtility.DisplayDialog( 46 | dialogTitle, 47 | "Character all setup\n\n" + 48 | "Please don't forget to set the ground tag to the ground of your level/scenes", 49 | "Awesome, will do" 50 | ); 51 | } 52 | } 53 | 54 | 55 | // Mashup of code from ctwheels & Leslie-Young by B0N3head 56 | // Dw about understanding this, it's just a tool for creating tags in editor for unity 57 | public void createTag(string tagName) 58 | { 59 | SerializedObject tagM = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); 60 | SerializedProperty tagsP = tagM.FindProperty("tags"); 61 | bool found = false; 62 | 63 | if (tagsP.arraySize < 10000) 64 | { 65 | for (int i = 0; i < tagsP.arraySize; i++) 66 | { 67 | SerializedProperty t = tagsP.GetArrayElementAtIndex(i); 68 | if (t.stringValue.Equals(tagName)) 69 | { 70 | found = true; 71 | Debug.Log($"The \"{tagName}\" tag already exists"); 72 | break; 73 | } 74 | } 75 | 76 | if (!found) 77 | { 78 | tagsP.InsertArrayElementAtIndex(0); 79 | SerializedProperty n = tagsP.GetArrayElementAtIndex(0); 80 | n.stringValue = tagName; 81 | Debug.Log($"The \"{tagName}\" tag has been added"); 82 | tagM.ApplyModifiedPropertiesWithoutUndo(); 83 | } 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Fps Movement Controller 2 | A simple to setup and easy to edit unity fps controller using rigidbody movement in c#. Almost every variable used in this player controller is customisable and accessible from the inspector **(No programing required)**. 3 | 4 | Feel free to use it in your own projects if you'd like! 5 | 6 | [Trello Link](https://trello.com/b/maiUD4Te/unity-fps-movementcontroller) to follow the progress of the next update 🎉 7 | ## Features 8 | 9 | - [x] Fully momentum based movement 10 | - [x] Customizable speeds for: 11 | - [x] Walking 12 | - [x] Sprinting 13 | - [x] Crouching 14 | - [x] Air speed 15 | - [x] Jumping 16 | - [x] Raycast ground detection 17 | - [X] [Coyote time](https://github.com/B0N3head/unity-fps-movement-controller/#visual-examples) 18 | - [X] [Jump cooldown](https://github.com/B0N3head/unity-fps-movement-controller/#visual-examples) 19 | - [x] [Variable jump height](https://github.com/B0N3head/unity-fps-movement-controller/#visual-examples) 20 | - [x] Crouching 21 | - [x] [Optional smoothed crouching using `lerp`](https://github.com/B0N3head/unity-fps-movement-controller/#visual-examples) 22 | - [x] Configurable to toggle or hold 23 | - [x] Allow crouching midair or on ground only 24 | - [x] Inspector 25 | - [x] Simple named vars (easy to understand) 26 | - [x] All vars contain quick descriptions within tool tips 27 | - [x] GUI based layer choice (choosing ground layer) 28 | - [x] Camera 29 | - [x] Variable smoothing of the camera 30 | - [x] Clamped look directions 31 | - [x] Variable sensitivity 32 | - [x] Cursor lock/unlock 33 | - [x] Configurable keys: (![See controls](https://github.com/B0N3head/unity-fps-movement-controller/#controls)) 34 | - [x] Jumping 35 | - [x] Crouching 36 | - [x] Sprinting 37 | - [x] Lock/Unlocking mouse 38 | - [x] Fast auto setup in one button button click 39 | - [x] Creates and sets up rigidbody 40 | - [x] Creates and sets up camera 41 | - [x] Sets unity physics gravity to -19 42 | - [x] Ask user if they want to set custom gravity 43 | - [x] Ask and create "Ground" tag if it does not exist 44 | 45 | ### Visual examples 46 | | Variable Jump Height & Jump Cooldown | Smoothed `lerp` Crouch vs Non-Smothed | Coyote Time *(Slowed & Exaggerated)* | 47 | | ------ | ------ |------ | 48 | | | | | 49 | 50 |
51 | 52 | ## Controls 53 | This script is currently setup with these default controls. 54 | These are all configurable from the editor. **(don't require any coding)** 55 | 56 | | Key(s) | Action | 57 | | ------ | ------ | 58 | | WSAD | Simple character movement | 59 | | Space | Jump | 60 | | Shift | Sprint | 61 | | Z* | Crouch | 62 | | Q | Lock/Unlock Mouse | 63 | 64 | ###### *CTRL creates issues when testing in editor so Z is used (ctrl + most keys = will run unity hotkey) 65 | 66 |
67 | 68 | ## How to setup the character 69 | 70 | 1. Download and add the files to your assets folder 71 | 72 | 73 | 74 | 2. Add a capsule to your scene 75 | 76 | 77 | 78 | 3. Add the Player Movement script through Component -> Player Movement and Camera Controller 79 | 80 | 81 | 82 | 4. Click the "Setup Player & World" button (I have not updated the old images yet, tho everything is in the same location) 83 | 84 | 85 | 86 | **Done**, you should now be left with something similar to the bellow 87 | 88 | 89 | 90 | ### One more thing 91 | **Please make sure that whatever the player is intended to stand/jump onto or from is set to the `Ground` tag.** 92 | 93 | When setting up the script, you will be prompted to let the script create the tag for you (I have not and prob wont create an algorythm/ai to detect what should and shouldn't be ground... so you will have to manually lable what should be ground). 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /readmeAssets/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/1.PNG -------------------------------------------------------------------------------- /readmeAssets/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/2.PNG -------------------------------------------------------------------------------- /readmeAssets/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/3.PNG -------------------------------------------------------------------------------- /readmeAssets/4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/4.PNG -------------------------------------------------------------------------------- /readmeAssets/5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/5.PNG -------------------------------------------------------------------------------- /readmeAssets/coyoteTime.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/coyoteTime.gif -------------------------------------------------------------------------------- /readmeAssets/crouching.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/crouching.gif -------------------------------------------------------------------------------- /readmeAssets/groundLayer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/groundLayer.gif -------------------------------------------------------------------------------- /readmeAssets/varJumpHeight.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B0N3head/unity-fps-movement-controller/75b1e7b793374b8dd76e26a093b39554aadf1539/readmeAssets/varJumpHeight.gif --------------------------------------------------------------------------------