eveposa.blogg.se

Unity character controller source code
Unity character controller source code









unity character controller source code

when the moveDirection is multiplied by deltaTime). Gravity is multiplied by deltaTime twice (once here, and once below If (Input.GetButton("Jump") & canMove & characterController.isGrounded) MoveDirection = (forward * curSpeedX) + (right * curSpeedY) Vector3 right = transform.TransformDirection(Vector3.right) īool isRunning = Input.GetKey(Ke圜ode.LeftShift) įloat curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0 įloat curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0 įloat movementDirectionY = moveDirection.y Vector3 forward = transform.TransformDirection(Vector3.forward) We are grounded, so recalculate move direction based on axes Public class SC_FPSController : MonoBehaviourĬursor.lockState = CursorLockMode.Locked

  • Create a new script, name it "SC_FPSController" and paste the code below inside it:.
  • unity character controller source code

  • Move the Main Camera inside the "FPSPlayer" Object and change its position to (0, 1.64, 0).
  • Remove Capsule Collider component from Capsule and change its position to (0, 1, 0).
  • unity character controller source code

  • Create new Capsule (GameObject -> 3D Object -> Capsule) and move it inside "FPSPlayer" Object.
  • Create a new Game Object (GameObject -> Create Empty) and name it "FPSPlayer".
  • To make an FPS controller, follow the steps below: In this post, I will be showing how to make an FPS controller in Unity that will handle camera rotation and player movement. With usual controls being W, A, S, D to walk, Mouse Look to look around, Space to jump, and Left Shift to sprint, allowing the player to freely move around the level. FPS (or First-Person Shooter) is a type of game where the main character is controlled from a first-person perspective.











    Unity character controller source code