void Awake() { cameraController = FindObjectOfType <ThirdPersonCameraController>(); movementController = FindObjectOfType <GabrielsMovementController>(); animatorController = FindObjectOfType <GabiesAnimationController>(); AudioManager.Instance.PlaySong(3, 0.2f); if (PlayerPrefs.GetInt("SaveHealth", 0) == 1) { Health = 100f; Stamina = 100f; PlayerPrefs.SetInt("SaveHealth", 0); } if (Time.timeScale == 0) { Time.timeScale = 1f; } if (gabie != null && gabie != this) { Destroy(gameObject); } else { gabie = this; } }
void Awake() { instance = this; cam = GetComponentInChildren <Camera> (); velocity = Vector3.zero; playerRef = playerObject; }
public static void Initialise() { if (thirdPersonCameraController == null) { thirdPersonCameraController = Camera.main.gameObject.AddComponent <ThirdPersonCameraController>(); EnableFirstPerson(); } }
// Start is called before the first frame update void Start() { lockCursor = false; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; menu = transform.GetChild(0).gameObject; cameraComponent = camera.GetComponent <ThirdPersonCameraController>(); }
void Update() { float mouseX = ThirdPersonCameraController.HandleAxisInputDelegate("Mouse X") * mouseSensitivity * Time.deltaTime; float mouseY = ThirdPersonCameraController.HandleAxisInputDelegate("Mouse Y") * mouseSensitivity * Time.deltaTime; xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, -70f, 70f); transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); playerBody.Rotate(Vector3.up * mouseX); }
public CameraState_Manual(ThirdPersonCameraController controller) { this.controller = controller; }
void Awake() { instance = this; cam = GetComponentInChildren <Camera> (); }
public CameraState_Automatic(ThirdPersonCameraController controller) { this.controller = controller; }
void FixedUpdate() { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); float inputModifyFactor = (inputX != 0.0f && inputY != 0.0f && movSettings.limitDiagonalSpeed) ? .7071f : 1.0f; if (grounded) { bool sliding = false; //Raycast to check for a slope to slide on. if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance)) { if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) { sliding = true; } } //check from the collider. else { Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit); if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) { sliding = true; } } //If the player fell from a high place, damage. //Also reset jumps. if (falling) { falling = false; remainingJumps = jumpSettings.jumpCount; if (myTransform.position.y < fallStartLevel - jumpSettings.fallDamageThreshold) { FallingDamageAlert(fallStartLevel - myTransform.position.y); } } //If run key is down runSpeed, else walkSpeed. speed = Input.GetButton("Run") ? movSettings.runSpeed : movSettings.walkSpeed; // If sliding (and it's allowed), or if we're on an object tagged "Slide", get a vector pointing down the slope we're on if ((sliding && movSettings.slideOnSlopes) || (movSettings.slideOnSlopes && hit.collider.tag == "Slide")) { Vector3 hitNormal = hit.normal; moveDirection = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z); Vector3.OrthoNormalize(ref hitNormal, ref moveDirection); moveDirection *= movSettings.slideSpeed; playerControl = false; } // Otherwise recalculate moveDirection directly from axes, adding a bit of -y to avoid bumping down inclines else { moveDirection = new Vector3(inputX * inputModifyFactor, -movSettings.antiBumpFactor, inputY * inputModifyFactor); moveDirection = myTransform.TransformDirection(moveDirection) * speed; playerControl = true; } // Jump! But only if the jump button has been released and player has been grounded for a given number of frames if (Input.GetButton("Jump") && remainingJumps > 0 && jumpCooldownTimeStamp <= Time.time) { remainingJumps--; moveDirection.y = jumpSettings.jumpVelocity; jumpCooldownTimeStamp = Time.time + jumpSettings.jumpCooldownSeconds; } } else { // If we stepped over a cliff or something, set the height at which we started falling if (!falling) { falling = true; fallStartLevel = myTransform.position.y; } if (Input.GetButton("Jump") && remainingJumps > 0 && jumpCooldownTimeStamp <= Time.time) { remainingJumps--; moveDirection.y = jumpSettings.jumpVelocity; jumpCooldownTimeStamp = Time.time + jumpSettings.jumpCooldownSeconds; falling = false; } // If air control is allowed, check movement but don't touch the y component if (jumpSettings.airControl && playerControl) { moveDirection.x = inputX * speed * inputModifyFactor; moveDirection.z = inputY * speed * inputModifyFactor; moveDirection = myTransform.TransformDirection(moveDirection); } } // Apply gravity moveDirection.y -= jumpSettings.gravity * Time.deltaTime; //If the character is moving, center the camera and update rotation camController = GameObject.FindGameObjectWithTag("cameraPoint").GetComponent <CameraController>(); if (camController is ThirdPersonCameraController && ((ThirdPersonCameraController)camController).overrideWalking) { //Cast camController to ThirdPersonCamController. ThirdPersonCameraController thirdPersonCamController = (ThirdPersonCameraController)camController; if (inputX != 0 || inputY != 0) { if (!thirdPersonCamController.walking) { //Make the player face the camera. gameObject.transform.eulerAngles = new Vector3(0, camController.camPoint.gameObject.transform.eulerAngles.y, 0); } thirdPersonCamController.walking = true; thirdPersonCamController.CenterCamPointAxisY(); } else { thirdPersonCamController.walking = false; } } // Move the controller, and set grounded true or false depending on whether we're standing on something if (!camController.preventMovement) { grounded = (characterController.Move(moveDirection * Time.deltaTime) & CollisionFlags.Below) != 0; } }
public CameraState_Idle(ThirdPersonCameraController controller) { this.controller = controller; }