├── .gitattributes ├── .gitignore ├── Advanced 2D Controller ├── Advanced 2D Controller │ ├── Scripts │ │ ├── Identifiers │ │ │ ├── Ladder.cs │ │ │ ├── MovingPlatform.cs │ │ │ └── Slope.cs │ │ ├── LadderManager.cs │ │ └── TwoDController.cs │ └── Tutorials │ │ └── MP4 │ │ ├── Controller Setup - Basic Movement.mp4 │ │ ├── Controller Setup - Dashing.mp4 │ │ ├── Controller Setup - Jetpack.mp4 │ │ ├── Controller Setup - Jumping.mp4 │ │ ├── Controller Setup - Ladders.mp4 │ │ ├── Controller Setup - Moving Platforms.mp4 │ │ └── Controller Setup - Slopes.mp4 └── Editor │ └── CustomInspector.cs ├── LICENSE ├── README.md └── coffee.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.meta 28 | 29 | # Unity3D Video Generated Files 30 | *.db 31 | 32 | # Unity3D Generated File On Crash Reports 33 | sysinfo.txt 34 | 35 | # Builds 36 | *.apk 37 | *.unitypackage 38 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Scripts/Identifiers/Ladder.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [AddComponentMenu("Advanced Platformer Controller/ Ladder")] 5 | public class Ladder : MonoBehaviour { 6 | 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Scripts/Identifiers/MovingPlatform.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [AddComponentMenu("Advanced Platformer Controller/ Moving Platform")] 5 | public class MovingPlatform : MonoBehaviour { 6 | 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Scripts/Identifiers/Slope.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [AddComponentMenu("Advanced Platformer Controller/ Slope")] 5 | public class Slope : MonoBehaviour 6 | { 7 | public bool invertRotation; 8 | } 9 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Scripts/LadderManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [AddComponentMenu("Advanced Platformer Controller/ Ladder Manager")] 4 | public class LadderManager : MonoBehaviour { 5 | 6 | public TwoDController controller; 7 | 8 | private bool laddersEnabled; 9 | 10 | private bool isClimbingLadder; 11 | 12 | void Start () 13 | { 14 | controller = GetComponentInParent(); 15 | 16 | Physics.IgnoreCollision(GetComponent(), controller.GetComponent() ); 17 | } 18 | 19 | void FixedUpdate () 20 | { 21 | if (controller.ladderType == TwoDController.LadderType.Activated) 22 | { 23 | laddersEnabled = true; 24 | } else 25 | { 26 | laddersEnabled = false; 27 | } 28 | } 29 | 30 | void OnTriggerEnter (Collider other) 31 | { 32 | if (laddersEnabled && other.GetComponent() != null) 33 | { 34 | controller.isClimbing = true; 35 | } else 36 | { 37 | controller.isClimbing = false; 38 | } 39 | } 40 | 41 | void OnTriggerExit () 42 | { 43 | controller.isClimbing = false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Scripts/TwoDController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [System.Serializable] 5 | [AddComponentMenu("Advanced Platformer Controller/ Platformer Controller")] 6 | [RequireComponent(typeof(CharacterController))] 7 | public class TwoDController : MonoBehaviour { 8 | 9 | #region Variables 10 | 11 | private Vector3 startRotation; 12 | 13 | public enum MoveType 14 | { 15 | Sprint, 16 | Crouch, 17 | Sprint_Crouch, 18 | None 19 | } 20 | 21 | public enum JumpType 22 | { 23 | Jump, 24 | Jump_DoubleJump, 25 | None 26 | } 27 | 28 | public enum JetpackType 29 | { 30 | Activated, 31 | Not_Activated 32 | } 33 | 34 | public enum LadderType 35 | { 36 | Activated, 37 | Not_Activated 38 | } 39 | 40 | public enum DashType 41 | { 42 | Activated, 43 | Not_Activated 44 | } 45 | 46 | /// 47 | /// Axis to use for Horizontal movement. 48 | /// 49 | public string axis; 50 | 51 | /// 52 | /// Axis to use for ladder climbing. 53 | /// 54 | public string ladderAxis; 55 | 56 | public MoveType playerMoveType; 57 | public JumpType playerJumpType; 58 | public JetpackType jetpackType; 59 | public LadderType ladderType; 60 | public DashType dashType; 61 | 62 | /// 63 | /// Vector3 that will serve as velocity. 64 | /// 65 | public Vector3 moveDirection = Vector3.zero; 66 | 67 | /// 68 | /// Speed of the controller. 69 | /// 70 | public float speed; 71 | 72 | /// 73 | /// Speed when crouching. 74 | /// 75 | public float crouchSpeed; 76 | 77 | /// 78 | /// Speed when sprinting. 79 | /// 80 | public float sprintSpeed; 81 | 82 | /// 83 | /// Speed while climbing ladders. 84 | /// 85 | public float ladderSpeed; 86 | 87 | /// 88 | /// Graavity to be applied. 89 | /// 90 | public float gravity; 91 | 92 | /// 93 | /// Force of a jump. 94 | /// 95 | public float jumpForce; 96 | 97 | /// 98 | /// Force of a double jump. 99 | /// 100 | public float doubleJumpForce; 101 | 102 | /// 103 | /// Is the controller crouching? 104 | /// 105 | public bool isCrouching; 106 | 107 | /// 108 | /// Is the controller sprinting? 109 | /// 110 | public bool isSprinting; 111 | 112 | /// 113 | /// Is the controller double-jumping? 114 | /// 115 | public bool doubleJumping; 116 | 117 | /// 118 | // Set to true if the controller is facing left. 119 | /// 120 | public bool facingLeft = false; 121 | 122 | /// 123 | /// Set to true if the controller is fight right. 124 | /// 125 | public bool facingRight = true; 126 | 127 | /// 128 | /// Set to true if the controller can double jump in this moment. 129 | /// 130 | private bool canDoubleJump; 131 | 132 | 133 | /// 134 | /// Speed of the controller at Start. 135 | /// 136 | private float normalSpeed; 137 | 138 | /// 139 | /// True if the controller is currently on a ladder. 140 | /// 141 | public bool isClimbing; 142 | 143 | /// 144 | /// True if the jetpack is being used. 145 | /// 146 | public bool jetPackEnabled; 147 | 148 | /// 149 | /// Duration of the jetpack. 150 | /// 151 | public float jetpackDuration; 152 | 153 | /// 154 | /// Time that it takes to fully recharge the jetpack (seconds). 155 | /// 156 | public float jetpackRecharge; 157 | 158 | /// 159 | /// Jetpack duration at Start. 160 | /// 161 | private float defaultJetDur; 162 | 163 | /// 164 | /// Force that the jetpack applies. 165 | /// 166 | public float jetForce; 167 | 168 | /// 169 | /// Controller attached to this gameobject. 170 | /// 171 | private CharacterController playerController; 172 | 173 | /// 174 | /// Jump button. 175 | /// 176 | public string jumpKey; 177 | 178 | /// 179 | /// Jetpack button. 180 | /// 181 | public string jetpackKey; 182 | 183 | /// 184 | /// Sprint button. 185 | /// 186 | public string sprintKey; 187 | 188 | /// 189 | /// Crouch button. 190 | /// 191 | public string crouchKey; 192 | 193 | /// 194 | /// Dash button. 195 | /// 196 | public string dashKey = "Dash"; 197 | 198 | /// 199 | /// Duration of the dash in seconds. 200 | /// 201 | public float dashDuration = .1f; 202 | 203 | /// 204 | /// Force of the dash. 205 | /// 206 | public float dashForce = 5; 207 | 208 | /// 209 | /// Delay between dashes. 210 | /// 211 | public float dashCooldown = 1; 212 | 213 | // Used internally for dash control. 214 | bool isDashingLeft; 215 | bool isDashingRight; 216 | bool canDash = true; 217 | 218 | 219 | 220 | #endregion Variables 221 | 222 | void Start () 223 | { 224 | playerController = GetComponent(); 225 | facingRight = true; 226 | normalSpeed = speed; 227 | 228 | startRotation = transform.eulerAngles; 229 | defaultJetDur = jetpackDuration; 230 | } 231 | 232 | void Update() 233 | { 234 | // Jetpack =========== 235 | 236 | jetpackDuration = Mathf.Clamp(jetpackDuration, 0, defaultJetDur); 237 | 238 | if (jetPackEnabled && jetpackDuration > 0 && !isClimbing) 239 | { 240 | if (jetpackType == JetpackType.Activated) 241 | { 242 | if (Input.GetButton(jetpackKey)) 243 | { 244 | if (jetPackEnabled && !isClimbing) 245 | { 246 | ApplyJetForce(); 247 | } 248 | } 249 | } 250 | } 251 | 252 | // ============ Jetpack 253 | 254 | // Dashing ========== 255 | 256 | if (dashType == DashType.Activated) 257 | { 258 | if (Input.GetButtonDown(dashKey)) 259 | { 260 | if (moveDirection.x == 1 && canDash) 261 | { 262 | StartCoroutine(Dash(0)); 263 | StartCoroutine(DashCooldown()); 264 | } 265 | else if (moveDirection.x == -1 && canDash) 266 | { 267 | StartCoroutine(Dash(1)); 268 | StartCoroutine(DashCooldown()); 269 | } 270 | } 271 | } 272 | 273 | if (!isDashingRight && !isDashingLeft) 274 | { 275 | moveDirection.x = Input.GetAxisRaw(axis); 276 | } 277 | else if (isDashingRight) 278 | { 279 | moveDirection.x = dashForce; 280 | } 281 | else 282 | { 283 | moveDirection.x = -dashForce; 284 | } 285 | 286 | // ========= Dashing 287 | 288 | // Climbing ======== 289 | 290 | if (isClimbing) 291 | { 292 | moveDirection.y = Input.GetAxisRaw(ladderAxis) * ladderSpeed; 293 | } 294 | 295 | // ========= Climbing 296 | 297 | // Reseting ========= 298 | 299 | if (playerController.isGrounded) 300 | { 301 | doubleJumping = false; 302 | jetPackEnabled = false; 303 | } 304 | else if (transform.parent != null) 305 | { 306 | transform.SetParent(null); //Detach from moving platform 307 | } 308 | 309 | // ========= Resetting 310 | 311 | //Jumping ============ 312 | 313 | if (playerJumpType == JumpType.Jump || playerJumpType == JumpType.Jump_DoubleJump) 314 | { 315 | if (Input.GetButtonDown(jumpKey)) 316 | { 317 | JumpCheck(); 318 | } 319 | } 320 | 321 | // =========== Jumping 322 | 323 | 324 | // Gravity ============= 325 | 326 | if (moveDirection.y > -2 && !isClimbing) 327 | { 328 | moveDirection.y -= gravity * Time.deltaTime; 329 | } 330 | 331 | // ============= Gravity 332 | 333 | 334 | 335 | 336 | 337 | if (!jetPackEnabled && jetpackDuration < defaultJetDur && playerController.isGrounded) 338 | { 339 | RechargeJetpack(); 340 | } 341 | 342 | //Sprinting and Crouching 343 | if (playerController.isGrounded) 344 | { 345 | if (playerMoveType == MoveType.Sprint_Crouch || playerMoveType == MoveType.Crouch) 346 | { 347 | if (Input.GetButtonDown(crouchKey)) 348 | { 349 | Crouch(); 350 | } 351 | } 352 | 353 | if (playerMoveType == MoveType.Sprint_Crouch || playerMoveType == MoveType.Sprint) 354 | { 355 | if (Input.GetButtonDown(sprintKey)) 356 | { 357 | Sprint(); 358 | } 359 | } 360 | } 361 | 362 | if (playerMoveType == MoveType.Sprint_Crouch || playerMoveType == MoveType.Crouch) 363 | { 364 | if (Input.GetButtonUp(crouchKey) || Input.GetButtonUp(sprintKey)) 365 | { 366 | ResetSpeed(); 367 | } 368 | } 369 | 370 | 371 | if (moveDirection.x < 0 && !facingLeft) 372 | { 373 | FlipLeft(); 374 | } 375 | else if (moveDirection.x > 0 && !facingRight) 376 | { 377 | FlipRight(); 378 | } 379 | 380 | 381 | if ((playerController.collisionFlags & CollisionFlags.Above) != 0) 382 | { 383 | moveDirection.y = 0; 384 | } 385 | 386 | ApplyMovement(); 387 | 388 | } 389 | 390 | private void ApplyMovement () 391 | { 392 | 393 | playerController.Move(moveDirection * speed * Time.deltaTime); 394 | } 395 | 396 | private void JumpCheck () 397 | { 398 | if (playerController.isGrounded && !isCrouching ) 399 | { 400 | Jump(); 401 | } 402 | else if (canDoubleJump && playerJumpType == JumpType.Jump_DoubleJump && !playerController.isGrounded) 403 | { 404 | DoubleJump(); 405 | } 406 | 407 | } 408 | 409 | private void Jump () 410 | { 411 | moveDirection.y = (jumpForce); 412 | 413 | canDoubleJump = true; 414 | 415 | if (jetpackType == JetpackType.Activated && playerJumpType != JumpType.Jump_DoubleJump) 416 | { 417 | StartCoroutine(ActivateJetpack()); 418 | } 419 | } 420 | 421 | private void DoubleJump () 422 | { 423 | moveDirection.y = doubleJumpForce; 424 | doubleJumping = true; 425 | canDoubleJump = false; 426 | 427 | if (jetpackType == JetpackType.Activated) 428 | { 429 | StartCoroutine(ActivateJetpack()); 430 | } 431 | } 432 | 433 | 434 | public void FlipLeft () 435 | { 436 | if (!facingLeft) 437 | { 438 | facingLeft = true; 439 | facingRight = false; 440 | Vector3 theScale = transform.localScale; 441 | theScale.x *= -1; 442 | transform.localScale = theScale; 443 | } 444 | } 445 | 446 | public void FlipRight () 447 | { 448 | if (!facingRight) 449 | { 450 | facingRight = true; 451 | facingLeft = false; 452 | Vector3 theScale = transform.localScale; 453 | theScale.x *= -1; 454 | transform.localScale = theScale; 455 | } 456 | } 457 | 458 | 459 | 460 | private IEnumerator ActivateJetpack () 461 | { 462 | yield return new WaitForSeconds(.3f); 463 | 464 | if (jetpackDuration > 0) 465 | jetPackEnabled = true; 466 | } 467 | 468 | 469 | 470 | private void ApplyJetForce () 471 | { 472 | moveDirection.y += jetForce; 473 | jetpackDuration -= Time.deltaTime; 474 | } 475 | 476 | private void RechargeJetpack () 477 | { 478 | jetpackDuration += (defaultJetDur / jetpackRecharge) * Time.deltaTime; 479 | } 480 | 481 | 482 | private void ResetSpeed() 483 | { 484 | speed = normalSpeed; 485 | 486 | isSprinting = false; 487 | isCrouching = false; 488 | } 489 | 490 | private void Sprint () 491 | { 492 | speed = sprintSpeed; 493 | 494 | isSprinting = true; 495 | isCrouching = false; 496 | } 497 | 498 | private void Crouch () 499 | { 500 | speed = crouchSpeed; 501 | 502 | isSprinting = false; 503 | isCrouching = true; 504 | } 505 | 506 | 507 | 508 | private void CheckMovingPlatform (ControllerColliderHit other) 509 | { 510 | // Moving Platforms 511 | if (other.gameObject.GetComponent() != null && (playerController.collisionFlags & CollisionFlags.Below) != 0) 512 | { 513 | gameObject.transform.SetParent(other.transform); 514 | } 515 | else 516 | { 517 | gameObject.transform.SetParent(null); 518 | } 519 | } 520 | 521 | private void CheckSlopes (ControllerColliderHit other) 522 | { 523 | if (other.gameObject.GetComponent() != null && (playerController.collisionFlags & CollisionFlags.Below) != 0) 524 | { 525 | Slope slope = other.gameObject.GetComponent(); 526 | 527 | if (slope.invertRotation) 528 | { 529 | transform.localEulerAngles = new Vector3(startRotation.x, startRotation.y, slope.gameObject.transform.localEulerAngles.z); 530 | } else 531 | { 532 | transform.localEulerAngles = new Vector3(startRotation.x, startRotation.y, -slope.gameObject.transform.localEulerAngles.z); 533 | } 534 | 535 | } 536 | else 537 | { 538 | transform.localEulerAngles = startRotation; 539 | } 540 | } 541 | 542 | IEnumerator Dash (int direction) 543 | { 544 | if (direction == 0) 545 | { 546 | isDashingRight = true; 547 | } else 548 | { 549 | isDashingLeft = true; 550 | } 551 | 552 | yield return new WaitForSeconds(dashDuration); 553 | 554 | isDashingRight = false; 555 | isDashingLeft = false; 556 | } 557 | 558 | IEnumerator DashCooldown () 559 | { 560 | canDash = false; 561 | 562 | yield return new WaitForSeconds(dashCooldown); 563 | 564 | canDash = true; 565 | } 566 | 567 | void OnControllerColliderHit(ControllerColliderHit other) 568 | { 569 | CheckMovingPlatform(other); 570 | 571 | CheckSlopes(other); 572 | } 573 | } 574 | -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Basic Movement.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Basic Movement.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Dashing.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Dashing.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Jetpack.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Jetpack.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Jumping.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Jumping.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Ladders.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Ladders.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Moving Platforms.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Moving Platforms.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Slopes.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/Advanced 2D Controller/Advanced 2D Controller/Tutorials/MP4/Controller Setup - Slopes.mp4 -------------------------------------------------------------------------------- /Advanced 2D Controller/Editor/CustomInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityEditor; 4 | 5 | 6 | [CustomEditor(typeof(TwoDController))] 7 | public class CustomInspector : Editor { 8 | 9 | bool showPosition; 10 | 11 | 12 | TwoDController controller; 13 | 14 | SerializedProperty horizontalAxis; 15 | SerializedProperty ladderAxis; 16 | 17 | SerializedProperty jumpButton; 18 | SerializedProperty sprintButton; 19 | SerializedProperty crouchButton; 20 | SerializedProperty jetpackButton; 21 | SerializedProperty dashButton; 22 | 23 | SerializedProperty moveType; 24 | SerializedProperty jumpType; 25 | SerializedProperty jetpackType; 26 | SerializedProperty ladderType; 27 | SerializedProperty dashType; 28 | 29 | 30 | SerializedProperty speed; 31 | SerializedProperty crouchSpeed; 32 | SerializedProperty sprintSpeed; 33 | 34 | SerializedProperty gravity; 35 | 36 | SerializedProperty jumpForce; 37 | SerializedProperty doubleJumpForce; 38 | 39 | SerializedProperty ladderSpeed; 40 | 41 | SerializedProperty jetpackDuration; 42 | SerializedProperty jetpackRecharge; 43 | SerializedProperty jetpackForce; 44 | 45 | SerializedProperty dashDuration; 46 | SerializedProperty dashForce; 47 | SerializedProperty dashCooldown; 48 | 49 | void OnEnable () 50 | { 51 | horizontalAxis = serializedObject.FindProperty("axis"); 52 | ladderAxis = serializedObject.FindProperty("ladderAxis"); 53 | 54 | jumpButton = serializedObject.FindProperty("jumpKey"); 55 | sprintButton = serializedObject.FindProperty("sprintKey"); 56 | crouchButton = serializedObject.FindProperty("crouchKey"); 57 | jetpackButton = serializedObject.FindProperty("jetpackKey"); 58 | dashButton = serializedObject.FindProperty("dashKey"); 59 | 60 | moveType = serializedObject.FindProperty("playerMoveType"); 61 | jumpType = serializedObject.FindProperty("playerJumpType"); 62 | jetpackType = serializedObject.FindProperty("jetpackType"); 63 | ladderType = serializedObject.FindProperty("ladderType"); 64 | dashType = serializedObject.FindProperty("dashType"); 65 | 66 | speed = serializedObject.FindProperty("speed"); 67 | crouchSpeed = serializedObject.FindProperty("crouchSpeed"); 68 | sprintSpeed = serializedObject.FindProperty("sprintSpeed"); 69 | 70 | dashForce = serializedObject.FindProperty("dashForce"); 71 | dashDuration = serializedObject.FindProperty("dashDuration"); 72 | dashCooldown = serializedObject.FindProperty("dashCooldown"); 73 | 74 | gravity = serializedObject.FindProperty("gravity"); 75 | 76 | jumpForce = serializedObject.FindProperty("jumpForce"); 77 | doubleJumpForce = serializedObject.FindProperty("doubleJumpForce"); 78 | 79 | ladderSpeed = serializedObject.FindProperty("ladderSpeed"); 80 | 81 | jetpackDuration = serializedObject.FindProperty("jetpackDuration"); 82 | jetpackRecharge = serializedObject.FindProperty("jetpackRecharge"); 83 | jetpackForce = serializedObject.FindProperty("jetForce"); 84 | } 85 | 86 | public override void OnInspectorGUI () 87 | { 88 | serializedObject.Update(); 89 | 90 | 91 | EditorGUILayout.LabelField("Settings: ", EditorStyles.boldLabel); 92 | 93 | EditorGUILayout.Space(); 94 | 95 | EditorGUILayout.PropertyField(moveType, new GUIContent("Movement ")); 96 | EditorGUILayout.PropertyField(jumpType, new GUIContent("Jumping ")); 97 | EditorGUILayout.PropertyField(jetpackType, new GUIContent("Jetpack ")); 98 | EditorGUILayout.PropertyField(ladderType, new GUIContent("Ladders ")); 99 | EditorGUILayout.PropertyField(dashType, new GUIContent("Dashing ")); 100 | 101 | EditorGUILayout.Space(); 102 | EditorGUILayout.Space(); 103 | 104 | EditorGUILayout.LabelField("Controls ", EditorStyles.boldLabel); 105 | 106 | EditorGUILayout.Space(); 107 | EditorGUILayout.Space(); 108 | 109 | 110 | EditorGUILayout.PropertyField(horizontalAxis, new GUIContent ("Horizontal Axis ")); 111 | 112 | EditorGUILayout.Space(); 113 | 114 | if (ladderType.enumValueIndex == 0) 115 | { 116 | EditorGUILayout.PropertyField(ladderAxis, new GUIContent("Ladder Axis ")); 117 | EditorGUILayout.Space(); 118 | } 119 | 120 | 121 | 122 | if (jumpType.enumValueIndex == 0 || jumpType.enumValueIndex == 1) 123 | { 124 | EditorGUILayout.PropertyField(jumpButton, new GUIContent("Jump Button ")); 125 | EditorGUILayout.Space(); 126 | } 127 | 128 | 129 | 130 | if (moveType.enumValueIndex == 0 || moveType.enumValueIndex == 2) 131 | { 132 | EditorGUILayout.PropertyField(sprintButton, new GUIContent("Sprint Button ")); 133 | EditorGUILayout.Space(); 134 | } 135 | 136 | 137 | 138 | if (moveType.enumValueIndex == 1 || moveType.enumValueIndex == 2) 139 | { 140 | EditorGUILayout.PropertyField(crouchButton, new GUIContent("Crouch Button ")); 141 | EditorGUILayout.Space(); 142 | } 143 | 144 | 145 | 146 | if (jetpackType.enumValueIndex == 0) 147 | { 148 | EditorGUILayout.PropertyField(jetpackButton, new GUIContent("Jetpack Button ")); 149 | EditorGUILayout.Space(); 150 | } 151 | 152 | if (dashType.enumValueIndex == 0) 153 | { 154 | EditorGUILayout.PropertyField(dashButton, new GUIContent("Dash Button ")); 155 | EditorGUILayout.Space(); 156 | } 157 | 158 | EditorGUILayout.Space(); 159 | EditorGUILayout.Space(); 160 | 161 | EditorGUILayout.LabelField("Modifiers", EditorStyles.boldLabel); 162 | 163 | EditorGUILayout.Space(); 164 | 165 | EditorGUILayout.PropertyField(speed, new GUIContent("Speed")); 166 | 167 | if (moveType.enumValueIndex == 0 || moveType.enumValueIndex == 2) 168 | EditorGUILayout.PropertyField(sprintSpeed, new GUIContent("Sprint Speed ")); 169 | 170 | if (moveType.enumValueIndex == 1 || moveType.enumValueIndex == 2) 171 | EditorGUILayout.PropertyField(crouchSpeed, new GUIContent("Crouch Speed ")); 172 | 173 | if (ladderType.enumValueIndex == 0) 174 | EditorGUILayout.PropertyField (ladderSpeed, new GUIContent("Ladder Speed ")); 175 | 176 | EditorGUILayout.Space (); 177 | EditorGUILayout.Space(); 178 | EditorGUILayout.Space(); 179 | 180 | EditorGUILayout.LabelField("Gravity", EditorStyles.boldLabel); 181 | 182 | EditorGUILayout.Space(); 183 | 184 | EditorGUILayout.PropertyField(gravity, new GUIContent("Gravity ")); 185 | 186 | if (jumpType.enumValueIndex == 0 || jumpType.enumValueIndex == 1) 187 | EditorGUILayout.PropertyField(jumpForce, new GUIContent("Jump Force ")); 188 | 189 | if (jumpType.enumValueIndex == 1) 190 | EditorGUILayout.PropertyField(doubleJumpForce, new GUIContent("Double Jump Force ")); 191 | 192 | EditorGUILayout.Space(); 193 | EditorGUILayout.Space(); 194 | EditorGUILayout.Space(); 195 | 196 | if (jetpackType.enumValueIndex == 0) 197 | { 198 | EditorGUILayout.LabelField("Jetpack", EditorStyles.boldLabel); 199 | 200 | EditorGUILayout.PropertyField(jetpackDuration, new GUIContent("Jetpack Duration ")); 201 | 202 | EditorGUILayout.PropertyField(jetpackForce, new GUIContent("Jetpack Force ")); 203 | 204 | EditorGUILayout.PropertyField(jetpackRecharge, new GUIContent("Jetpack Recharge Duration ")); 205 | 206 | EditorGUILayout.Space(); 207 | EditorGUILayout.Space(); 208 | } 209 | 210 | if (dashType.enumValueIndex == 0) 211 | { 212 | EditorGUILayout.LabelField("Dash", EditorStyles.boldLabel); 213 | 214 | EditorGUILayout.PropertyField(dashDuration, new GUIContent("Dash Duration ")); 215 | EditorGUILayout.PropertyField(dashForce, new GUIContent("Dash Force ")); 216 | EditorGUILayout.PropertyField(dashCooldown, new GUIContent("Dash Cooldown ")); 217 | 218 | EditorGUILayout.Space(); 219 | EditorGUILayout.Space(); 220 | } 221 | 222 | EditorGUILayout.Space(); 223 | EditorGUILayout.Space(); 224 | 225 | serializedObject.ApplyModifiedProperties(); 226 | 227 | } 228 | 229 | } 230 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 João Pedro Costa 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTML5 DEMO 2 | 3 | http://advancedcontrollerdemos.esy.es/DemoScene/DemoScene.html 4 | 5 | # Unity Platformer Controller 6 | 7 | ![Alt text](https://i.imgur.com/33xsbag.jpg "Generated Road with Spline Gizmo") 8 | 9 | A 2D / 2.5D controller for Unity. 10 | 11 | Supports most movement types - 12 | 13 | Walking 14 | 15 | Sprinting 16 | 17 | Crouching 18 | 19 | Jump / Double-Jump 20 | 21 | Ladders 22 | 23 | Jetpack 24 | 25 | Wall Jump [Beta, not yet included] 26 | 27 | Slopes 28 | 29 | Moving Platforms 30 | 31 | 32 | Supports All types of Controllers 33 | 34 | Custom Inspector 35 | 36 | ![Alt text](https://image.prntscr.com/image/LCJXYKowT9GUwxBVbq7NqQ.png "Generated Road with Spline Gizmo") 37 | 38 | 39 | # Beta Features 40 | 41 | Wall Jumping 42 | 43 | ![Alt text](https://image.prntscr.com/image/CHXyDTwKQuCqIlFwX05NPw.png "Generated Road with Spline Gizmo") 44 | 45 | 46 | Integrated State Machine 47 | 48 | ![Alt text](https://image.prntscr.com/image/He1l3_0fSLKFfiE_C72Jsg.png "Generated Road with Spline Gizmo") 49 | 50 | 51 | 52 | ![Alt text](https://i.imgur.com/IDf2Qlt.png "Ladders") 53 | 54 | ![Alt text](https://i.imgur.com/JHCVbTX.png "Generated Road with Spline Gizmo") 55 | 56 | ![Alt text](https://i.imgur.com/HPmfsIf.png "Ladders") 57 | 58 | # Consider buying me a coffee if you like my work (click the image) 59 | [![Foo](coffee.png)](https://www.buymeacoffee.com/ZcRuWpUBf) 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /coffee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Platformer-Controller/9db92e47e5a522bcbcbede5a2d451bd5a494044f/coffee.png --------------------------------------------------------------------------------