Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //bug that locks left strafe somehow
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MoveAndMouselookLRScript : MonoBehaviour
- {
- private Rigidbody rb;
- public float speed = 2000; //old remove?
- public float jumpForce = 500;
- bool jumping = false;
- private float maxSpeedX = 10;
- //private float maxSpeedY = 2000;
- private float maxSpeedZ = 10;
- private float runMultiplyer;
- private float godModeSpeed;
- private float xForce;
- private float zForce;
- [NonSerialized] public Vector3 force;
- private float pitch = 0.0F;
- private float yaw = 0.0F;
- [NonSerialized] public FacingDirection playerFacingDir;
- private float speedCap;
- private float mouseSensitivityX;
- [NonSerialized] public bool onGround;
- private int countMouse1 = 0;
- //private Vector3 platformForce;
- //Collider hanglingCol; not used rn
- [NonSerialized] public Vector3 cameraForward;
- [NonSerialized] public Vector3 cameraRight;
- //[SerializeField] List<Mapping> mapping; use this to define manually
- //FacingDirection FacingDirection; //predefined in enum
- void Start()
- {
- //hanglingCol = gameObject.transform.Find("ArmsPos").GetComponent<MeshCollider>(); not used rn
- rb = GetComponent<Rigidbody>();
- mouseSensitivityX = GameManager.gameManagerInstance.mouseSensitivityX;
- Cursor.visible = false;
- }
- private void Update()
- {
- //print("click count" + clicked);
- //camera rotation
- cameraForward = GetComponentInChildren<Camera>().transform.forward;
- cameraRight = GetComponentInChildren<Camera>().transform.right;
- //y not needed and needs to be 0
- cameraForward.y = 0;
- cameraRight.y = 0;
- //dono need to reasearch
- cameraForward = cameraForward.normalized;
- cameraRight = cameraRight.normalized;
- //needs to be in update in order to function
- onGround = GetComponentInChildren<GroundCheck>().onGround;
- //jump
- if (Input.GetButtonDown("Jump") && onGround)
- {
- jumping = true;
- Jump();
- }
- //disable jumping status
- if (onGround)
- {
- jumping = false;
- //GameManager.gameManagerInstance.lockMousePlayerRotate = false;
- }
- //enable god mode
- if (Input.GetKeyUp(KeyCode.Alpha0))
- {
- print("0");
- GameManager.gameManagerInstance.godModeEnabled = !GameManager.gameManagerInstance.godModeEnabled;
- }
- //camera oriantation + transomf orientation
- //transform.position += (cameraForward * force.y + cameraRight * force.x) * Time.deltaTime;
- //godmode stuff
- if (GameManager.gameManagerInstance.godModeEnabled)
- {
- if (Input.GetKey(KeyCode.E))
- {
- force = new Vector3(0, 1, 0);
- }
- if (Input.GetKey(KeyCode.Q))
- {
- force = new Vector3(0, -1, 0);
- }
- // +speed
- if (Input.GetKey("[+]"))
- {
- print("+speed");
- godModeSpeed += 0.1f;
- }
- // -speed
- if (Input.GetKey("[-]"))
- {
- print("-speed");
- godModeSpeed -= 0.1f;
- if (godModeSpeed < 1)
- {
- godModeSpeed = 1;
- }
- }
- }//god mode
- else
- {
- godModeSpeed = 1;
- }//end godmode
- // enable running
- if (Input.GetKey(KeyCode.LeftShift) && onGround)
- {
- runMultiplyer = 1.1f;
- speedCap = 25;
- }
- else if (onGround)
- {
- runMultiplyer = 1;
- speedCap = 10;
- }
- }//end update
- void FixedUpdate()
- {
- //lock/unlock mouse player rotation
- if(GameManager.gameManagerInstance.lockMousePlayerRotate == false)
- {
- //reset to 0 if player turns 360 with mouse
- if(yaw >= 70 || yaw <= -70){yaw = 0;}
- else
- {
- // mouse player rotation left/right
- yaw += Input.GetAxis("Mouse X");
- }
- }
- //left mousebutton counter
- if (Input.GetMouseButtonDown(0))
- {
- //Cursor.visible = false;
- //GameManager.gameManagerInstance.lockMousePlayerRotate = false;
- //Cursor.lockState = CursorLockMode.Locked;
- //countMouse1 = 0;
- }
- if (Input.GetMouseButtonDown(1))
- {
- countMouse1 ++;
- if(countMouse1 == 1)
- {
- Cursor.visible = true;
- GameManager.gameManagerInstance.lockMousePlayerRotate = true;
- Cursor.lockState = CursorLockMode.None;
- }
- if(countMouse1 > 1)
- {
- Cursor.visible = false;
- GameManager.gameManagerInstance.lockMousePlayerRotate = false;
- Cursor.lockState = CursorLockMode.Locked;
- countMouse1 = 0;
- }
- }
- //left mousebutton counter end
- }//end fixedUpdate
- void LateUpdate()
- {
- // rotate object to face mouse direction
- rb.transform.localEulerAngles = new Vector3(0.0f, yaw * mouseSensitivityX, 0.0F);
- //print("yaw: " + yaw + "mouse axis: " + Input.GetAxis("Mouse X"));
- if(yaw >= -5 && yaw <= 5) { playerFacingDir = FacingDirection.Forward; };
- if(yaw >= -20 && yaw <= -5) { playerFacingDir = FacingDirection.Left; };
- if(yaw >= -40 && yaw <= -20) { playerFacingDir = FacingDirection.Back; };
- if(yaw >= -60 && yaw <= -40) { playerFacingDir = FacingDirection.Right; };
- if(yaw >= -60 && yaw <= -60) { playerFacingDir = FacingDirection.Forward; };
- if(yaw >= -5 && yaw <= 5) { playerFacingDir = FacingDirection.Forward; };
- if(yaw >= 5 && yaw <= 20) { playerFacingDir = FacingDirection.Right; };
- if(yaw >= 20 && yaw <= 40) { playerFacingDir = FacingDirection.Back; };
- if(yaw >= 40 && yaw <= 60) { playerFacingDir = FacingDirection.Left; };
- if(yaw >= 60 && yaw <= 60) { playerFacingDir = FacingDirection.Forward; };
- //print("direction:" + playerFacingDir);
- }//end late update
- private void Jump()
- {
- transform.Translate(Vector3.up * Time.deltaTime * jumpForce);
- }//end jump
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement