void FixedUpdate() { MoveVector.CalculateRaw(); if (CheckGrounded()) { if (Input.GetKey(KeyCode.LeftShift)) { MoveVector.ApplySlideFriction(); } else { MoveVector.ApplyGroundFriction(); MoveVector.ApplyGroundMovement(); } } else { MoveVector.ApplyAirMovement(); //Only apply aerial friction forces when there is no springjoint, as to not mess with the forces involved if (!TryGetComponent(out SpringJoint _)) { MoveVector.ApplyAirFriction(); } } }
void Start() { PlayerRigidBody = GetComponent <Rigidbody>(); CameraFocusTransform = GameObject.Find("CameraFocus").GetComponent <Transform>(); CameraControlScript = GameObject.Find("CameraFocus").GetComponent <CameraController>(); MenuController = GameObject.Find("Canvas").GetComponent <GameObject>(); PlayerTransform = GetComponent <Transform>(); PlayerCapsuleCollider = GetComponent <CapsuleCollider>(); PlayerCapsuleMesh = GetComponent <MeshFilter>().mesh; //PlayerCrouchMesh = AssetDatabase.LoadAssetAtPath<Mesh>("Assets/Models/suzanne.fbx"); GrappleMask = LayerMask.GetMask("Terrain", "PickupItem", "Default"); LineRender = GetComponent <LineRenderer>(); LineRender.useWorldSpace = true; LineMat = LineRender.material; MoveVector.Initialise(PlayerRigidBody, CameraFocusTransform, PlayerCapsuleCollider); }
void Update() { //Debug Keys if (Input.GetKeyDown(KeyCode.Alpha1)) { CameraControlScript.AddShakeTrauma(3f); } if (Input.GetKeyDown(KeyCode.Alpha2)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } if (Input.GetKeyDown(KeyCode.Alpha3)) { Debug.Log("KeyCode.Alpha3"); } //jump if (CheckGrounded() && Input.GetKeyDown(KeyCode.Space)) { MoveVector.ApplyJumpForce(); } // Create SpringJoint Ray PlayerDirection = new Ray(CameraFocusTransform.position, CameraFocusTransform.rotation * Vector3.forward); if (Input.GetMouseButtonDown(1) && Physics.SphereCast(PlayerDirection, 0.2f, out RaycastHit RayHit, MaxGrappleDistance, GrappleMask) && !RayHit.transform.gameObject.CompareTag("NonGrapple")) { CreateSpringJoint(out PlayerSpringJoint, RayHit); } // Destroy SpringJoint if (Input.GetMouseButtonUp(1)) { Destroy(PlayerSpringJoint); } //linerendering if (TryGetComponent(out SpringJoint _)) { linepos[0] = PlayerRigidBody.transform.position + new Vector3(0f, 0.69f, 0f) + (CameraFocusTransform.rotation * new Vector3(-0.7f, 0f, 0.7f)); if (PlayerSpringJoint.connectedBody != null) { linepos[1] = PlayerSpringJoint.connectedBody.gameObject.transform.TransformPoint(PlayerSpringJoint.connectedAnchor); } else { linepos[1] = PlayerSpringJoint.connectedAnchor; } LineRender.SetPositions(linepos); LineMat.SetFloat("_Stretch", Mathf.Abs(Vector3.Distance(PlayerRigidBody.position, linepos[1]) - PlayerSpringJoint.maxDistance)); } else { linepos[0] = Vector3.zero; linepos[1] = Vector3.zero; LineRender.SetPositions(linepos); } if (Input.GetKeyDown(KeyCode.LeftShift)) { MoveVector.StartSlide(); } if (Input.GetKeyUp(KeyCode.LeftShift)) { MoveVector.EndSlide(); } }