Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [System.Serializable]
- public class CharacterMotor : MonoBehaviour
- {
- CharacterController characterController;
- //Transform transform;
- [Header("Movement")]
- [SerializeField]
- private float runSpeed;
- [SerializeField]
- private float jumpSpeed;
- [Header("Physics")]
- [SerializeField]
- private float gravity;
- public Vector3 movement = Vector3.zero;
- /*
- public CharacterMotor(CharacterMotor myMotor, CharacterController myController, Transform myTransform)
- {
- characterController = myController;
- transform = myTransform;
- runSpeed = myMotor.runSpeed;
- jumpSpeed = myMotor.jumpSpeed;
- gravity = myMotor.gravity;
- }
- */
- private void Start()
- {
- characterController = GetComponent<CharacterController>();
- }
- public bool IsGrounded()
- {
- return characterController.isGrounded;
- }
- public void Move(float horizontal, float vertical, bool jump)
- {
- if (IsGrounded())
- {
- Vector3 direction = new Vector3(horizontal, 0, vertical);
- if (direction.magnitude > 1)
- direction = direction.normalized;
- direction *= runSpeed;
- direction = transform.TransformDirection(direction);
- movement = direction;
- if (jump)
- {
- movement.y = jumpSpeed;
- }
- }
- movement.y = movement.y - (gravity * BoltNetwork.FrameDeltaTime);
- characterController.Move(movement * BoltNetwork.FrameDeltaTime);
- }
- public void MoveLocal(Vector3 m)
- {
- characterController.Move(m * BoltNetwork.FrameDeltaTime);
- }
- }
Add Comment
Please, Sign In to add comment