Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player_Motor : MonoBehaviour {
- public static Player_Motor Instance;
- public float verticalVelocity { get; set; }
- public float horizontalVelocity { get; set; }
- public float verticalForce = 6f;
- public float horizontalForce = 6f;
- public float drag = 2.0f;
- public Vector3 moveVector { get; set; }
- public Transform _Cam;
- float gravity = 21.8f;
- float terminalVelocity = 20.0f;
- void Awake() {
- Instance = this;
- }
- public void UpdateMotor () {
- ProcessMotion ();
- Debug.Log (moveVector);
- _Cam.transform.position = new Vector3 (transform.position.x, transform.position.y, _Cam.transform.position.z);
- }
- void ProcessMotion() {
- moveVector = transform.TransformDirection (moveVector);
- if (moveVector.magnitude > 1) {
- moveVector = Vector3.Normalize(moveVector);
- }
- horizontalVelocity = horizontalForce;
- moveVector = new Vector3 (horizontalVelocity, verticalVelocity, 0);
- applyDrag();
- applyGravity();
- Player_Controller.characterController.Move (moveVector * Time.deltaTime);
- }
- void applyDrag() {
- if (moveVector.x > 0) {
- moveVector = new Vector3(horizontalVelocity - drag * Time.deltaTime, moveVector.y, 0);
- }
- }
- void applyGravity() {
- if (moveVector.y > -terminalVelocity) {
- moveVector = new Vector3(moveVector.x, moveVector.y - gravity * Time.deltaTime, 0);
- }
- if (Player_Controller.characterController.isGrounded && moveVector.y < -1) {
- moveVector = new Vector3 (moveVector.x, -1, 0);
- }
- }
- public void Leap() {
- //if (Player_Controller.characterController.isGrounded ) {
- verticalVelocity = verticalForce;
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement