Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Player Move
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- private CharacterController _controller;
- private Vector2 _playerVelocity;
- private bool _groundedPlayer;
- public float _gravityValue;
- public float playerSpeed;
- public float jumpHeight;
- private void Start()
- {
- _controller = GetComponent<CharacterController>();
- }
- void FixedUpdate()
- {
- _groundedPlayer = _controller.isGrounded;
- if (_groundedPlayer && _playerVelocity.y < 0)
- {
- _playerVelocity.y = 0f;
- }
- Vector2 move = new Vector2(Input.GetAxis("Horizontal"), 0);
- _controller.Move(move * Time.fixedDeltaTime * playerSpeed);
- if (move != Vector2.zero)
- {
- gameObject.transform.forward = move;
- }
- if (Input.GetKey(KeyCode.X))
- {
- _controller.Move(move * Time.fixedDeltaTime * playerSpeed * 1.5f);
- }
- if (Input.GetKey(KeyCode.Space) && _groundedPlayer)
- {
- _playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * _gravityValue);
- }
- _playerVelocity.y += _gravityValue * Time.fixedDeltaTime;
- _controller.Move(_playerVelocity * Time.fixedDeltaTime);
- }
- }
Add Comment
Please, Sign In to add comment