private void TurnTowardsTarget() { Vector3 disToTarget = Player.transform.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; // get local angles BEFORE rotation Quaternion prevRot = transform.rotation; transform.rotation = targetRotation; // set rotation Vector3 euler2 = transform.localEulerAngles; // get local angles AFTER rotation if (lockRotationX) { euler2.x = euler1.x; // revert x to previous value } if (lockRotationY) { euler2.y = euler1.y; // revert y to previous value } if (lockRotationZ) { euler2.z = euler1.z; // revert z to previous value } transform.rotation = prevRot; // revert rotation // animate rotation transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); }
void Update() { // Use right click to drag the camera if (Input.GetButton("Fire2")) { // Change the pitch float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetPitch += mouseY * mouseSensitivityY; // Move the target to mouse targetYaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 3.5f, 20); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // Clamp the pitch degrees //Quaternion targetRotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); // Ease from current to target yaw = AnimMath.Slide(yaw, targetYaw, .05f); transform.rotation = Quaternion.Euler(pitch, yaw, 0); }
/// <summary> /// Slide turret's head back to where is was before /// </summary> private void PutTurretHome() { turretHead.localPosition = AnimMath.Slide(turretHead.localPosition, startPosTurretHead, .01f); // slides turret head to its start position Vector3 gunBarrel = turretHead.localPosition; // The gunBarrel get the localPosition Mathf.Clamp(turretHead.localPosition.x, gunBarrel.x = 0, gunBarrel.x = 0); // clamps turret head at x axis 0 }
private void AimAtPlayer() { Vector3 disToTarget = Player.transform.position - transform.position; Quaternion targetRot = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; Quaternion prevRot = transform.rotation; transform.rotation = targetRot; Vector3 euler2 = transform.localEulerAngles; if (lockRotationX) { euler2.x = euler1.x; } if (lockRotationY) { euler2.y = euler1.y; } if (lockRotationZ) { euler2.z = euler1.z; } transform.rotation = prevRot; transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); }
public void TurnTowardsPlayer() { Vector3 disToTarget = target.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); transform.rotation = AnimMath.Slide(transform.rotation, targetRotation, .01f); }
private void wiggleLegs() { float degrees = 45; float speed = 10; Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); alignment = Mathf.Abs(alignment); degrees *= AnimMath.Lerp(.25f, 1, alignment); //decrease 'degrees' when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); if (isShiftHeld) { //IMPLEMENT ARM SWING CODE } }
private void CheckForDeath() { if (healthCheck.isDying) // if sentry dies set trigger and keep from targeting player { dyingTrigger = true; isClose = false; //below sets it so the sentry is not a shootable target anymore for player isShootable.enabled = false; } //This triggers Death Animation which is the sentry spinning and shaking on the x and z rotations vigorusly if (dyingTrigger && dyingTimer > 0) { //Used mathf.Sin to make snetry rotate back and forth on x and z float betweenX = Mathf.Sin(Time.time * 40) * 25f; float betweenZ = Mathf.Sin(Time.time * 5) * 5f; turnVar += (turnSpeed + 100) * Time.deltaTime; // for y rotation Quaternion turnRot = Quaternion.Euler(betweenX, turnVar, betweenZ); //creates rotation transform.localRotation = AnimMath.Slide(transform.localRotation, turnRot, 0.001f); //smooth transition to rotation dyingTimer -= 1 * Time.deltaTime; //countdown } if (dyingTimer <= 0.01f) { Instantiate(parts, GunParent.position, GunParent.rotation); // this spawns death particles for sentry AudioP.Play(); } if (dyingTimer <= 0) // this destroys sentry object after death animation is complete { PlayerTargeting.enemiesKilled += 1; Destroy(GunParent.gameObject); } }
private void IdleAndAttackAnimation() { if (!isClose && idleTimer > 0 && !idleTrigger) // will make sentry go back to rotating idle animation if loses sight of player starting at 0,0,0 { lookingRotation = Quaternion.Euler(0, 0, 0); transform.localRotation = AnimMath.Slide(transform.localRotation, lookingRotation, 0.09f); idleTimer -= 1 * Time.deltaTime; } else if (isClose) //if player is close triggers part of attack animation, aka: sentry aiming at player when close { idleTimer = 1f; Vector3 disToTarget = Player.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); transform.localRotation = AnimMath.Slide(transform.localRotation, targetRotation, 0.001f); } else if (idleTrigger) //idle animation for sentry { turnVar += turnSpeed * Time.deltaTime; Quaternion dieRot = Quaternion.Euler(transform.localRotation.x, turnVar, transform.localRotation.z); transform.localRotation = AnimMath.Slide(transform.localRotation, dieRot, 0.01f); } if (idleTimer <= 0) //Makes it so there is a slight pause before turret goes from 0,0,0 to rotating in idle mode { idleTrigger = true; } }
/// <summary> /// Camera orbits around the player when the player moves the mouse around /// </summary> private void PlayerOrbitCamera() { // Gets 'float' input when the player moves the mouse float mX = Input.GetAxisRaw("Mouse X"); float mY = Input.GetAxisRaw("Mouse Y"); // Gets yaw and pitch yaw += mX * cameraSensitivityX; pitch += mY * cameraSensitivityY; if (IsTargeting()) // x-targeting: // if targeting { pitch = Mathf.Clamp(pitch, 15, 60); // find player yaw float playerYaw = moveScript.transform.eulerAngles.y; // clamp camera-rig yaw to playerYaw +- 30 yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40); } else // not targeting / free look { pitch = Mathf.Clamp(pitch, -10, 89); // clamps pitch to not get stuck } transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f); // makes camera have a smooth transition when moving it }
private void WiggleLegs() { float degrees = 45; float speed = 10; Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //Vector3.forward == new Vector3(0,0,1) alignment = Mathf.Abs(alignment); // flips negative numbers degrees *= AnimMath.Lerp(0.25f, 1, alignment); float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
private void PlayerOrbitCamera() { float mx = Input.GetAxisRaw("Mouse X"); float my = Input.GetAxisRaw("Mouse Y"); yaw += mx * cameraSenstivityX; pitch += my * cameraSenstivityY; if (IsTargeting()) { pitch = Mathf.Clamp(pitch, 15, 60); float playerYaw = moveScript.transform.eulerAngles.y; yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40); } else { pitch = Mathf.Clamp(pitch, -10, 89); } transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f); }
void Update() { if (Input.GetButton("Fire1")) // On Left Click { // Change Pitch on Mouse1 float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); // Scoll mousewheel to change DollyDis targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15f); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .95f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .95f); // EASE yaw = AnimMath.Slide(yaw, targetYaw, .95f); // EASE //Quaternion targetRotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // Slerp can be used for a spherical rotation transform.rotation = Quaternion.Euler(pitch, yaw, 0); }
private void TurnTowardsTheTarget() { if (playerTargeting && playerTargeting.target && playerTargeting.wantsToTarget) { Vector3 disToTarget = playerTargeting.target.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; Quaternion prevRot = transform.rotation; transform.rotation = targetRotation; Vector3 euler2 = transform.localEulerAngles; if (lockRotationX) { euler2.x = euler1.x; } if (lockRotationY) { euler2.y = euler1.y; } if (lockRotationZ) { euler2.z = euler1.z; } transform.rotation = prevRot; transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); } else { transform.localRotation = AnimMath.Slide(transform.localRotation, startingRotation, .05f); } }
/// <summary> /// This function animates the player's legs. /// </summary> private void WiggleLegs() { float degrees = 45; float speed = 10; // Get the vector perpendicular to the input direction. Vector3 inputDirectionLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirectionLocal, Vector3.up); // Check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirectionLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips the nmumber alignment = Mathf.Abs(alignment); // flips negative numbers /* * 1 = lots of movement * 0 = no movement * -1 = lots of movement */ // Remap alignment from .25 to 1, and multiply it by degrees. degrees *= AnimMath.Lerp(0.25f, 1, alignment); // Set the local rotation of the legs as the player moves. float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
/// <summary> /// Legs move around when the player moves to give the look that the player has a walk animation /// </summary> private void WiggleLegs() { float degrees = 45; // Degrees the legs would move to float speed = 10; // How has the legs are moving // Chancing the inputDirection direction from world space to local space Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal againts forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips negatve numbers alignment = Mathf.Abs(alignment); // flips negative numbers // 1 = yes! // 0 = no! // -1 = yes! degrees *= AnimMath.Lerp(.25f, 1, alignment); // decrease 'degrees' when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; // output values between... // Plays the animation using the slide function from AnimMath to give a sense of easing leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
void Update() { goToPlanet(); transform.position = AnimMath.Slide(transform.position, target, .05f); if (Input.GetButton("Fire2")) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetZoomDis += scroll * mouseScrollMultiplier; targetZoomDis = Mathf.Clamp(targetZoomDis, 2.5f, 15f); zoomDis = AnimMath.Slide(zoomDis, targetZoomDis, .05f); cam.transform.localPosition = new Vector3(0, 0, -zoomDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); yaw = AnimMath.Slide(yaw, targetYaw, .05f); transform.rotation = Quaternion.Euler(pitch, yaw, 0); }
// Update is called once per frame void Update() { if (Input.GetButton("Fire1")) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15f); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); //Ease cam.transform.localPosition = new Vector3(0, 0, -dollyDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //Ease yaw = AnimMath.Slide(yaw, targetYaw, .05f); //Ease transform.rotation = Quaternion.Euler(pitch, 0, 0); }
private void WiggleLegs() { float degrees = 45; float speed = 10; if (isTryingToMove) { Vector3 localDirection = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(localDirection, Vector3.up); //check localDirection against forward vector float alignment = Vector3.Dot(localDirection, Vector3.forward); //if (alignment < 0) alignment *= -1; // flip negative numbers alignment = Mathf.Abs(alignment); // flip negative numbers degrees *= AnimMath.Lerp(0.25f, 1, alignment); //decrease degree variable when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; // (-45 to 45) leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), 0.01f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), 0.01f); } else { leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.identity, 0.01f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.identity, 0.01f); } }
// Update is called once per frame void Update() { if (Input.GetButton("Fire2")) { // Changing the pitch float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetPitch += mouseY * mouseSensitivityY; targetYaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // Changing the rotation to match the pitch variable targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //EASE yaw = AnimMath.Slide(yaw, targetYaw, .05f); //EASE // Quaternion targetRotation transform.rotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // Could use .Slerp }
// Update is called once per frame void Update() { if (player) { Camera cam = Camera.main; Vector3 disToTarget = cam.transform.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; // get local angles BEFORE rotation Quaternion prevRot = transform.rotation; transform.rotation = targetRotation; // set rotation Vector3 euler2 = transform.localEulerAngles; // get local angles AFTER rotation euler2.y += 180; transform.rotation = prevRot; // revert rotation // animate rotation transform.localRotation = Quaternion.Euler(euler2); textInfo.alpha -= Time.deltaTime; transform.localPosition = AnimMath.Slide(transform.localPosition, new Vector3(transform.localPosition.x, transform.localPosition.y + 1, transform.localPosition.z), 0.1f); if (textInfo.alpha <= 0) { Destroy(gameObject); } } }
private void PlayerOrbitCamera() { float mx = Input.GetAxisRaw("Mouse X"); float my = Input.GetAxisRaw("Mouse Y"); yaw += mx * cameraSensitivityX; pitch += my * cameraSensitivityY; if (IsTargeting()) // z-targeting: { pitch = Mathf.Clamp(pitch, 15, 60); // find player yaw: float playerYaw = moveScript.transform.eulerAngles.y; // clamp camera-rig yaw to playerYaw +- 30: yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40); } else // not targeting / free look: { pitch = Mathf.Clamp(pitch, -10, 89); } transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f); }
// Update is called once per frame void Update() { if (Input.GetButton("Fire2")) { float mouseY = Input.GetAxis("Mouse Y"); targetPitch += mouseY * mouseSensitivityY; float mouseX = Input.GetAxis("Mouse X"); targetPitch2 += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDis += scroll * scrollSense; cam.transform.localPosition = new Vector3(0, 0, -dis); dis = AnimMath.Slide(dis, targetDis, .05f); //ease targetDis = Mathf.Clamp(targetDis, 2.5f, 15f); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //ease pitch2 = AnimMath.Slide(pitch2, targetPitch2, .05f); //eASE transform.rotation = Quaternion.Euler(pitch, pitch2, 0); }
// Update is called once per frame void Update() { lookAtPlanet(); transform.position = AnimMath.Slide(transform.position, target, .05f); if (Input.GetButton("Fire1")) { float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); pitch -= mouseY * mouseSensitivityY; yaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis -= scroll * mouseScrollMult; targetDollyDis = Mathf.Clamp(targetDollyDis, 5, 500); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // changing rotation to match the pitch variable: pitch = Mathf.Clamp(pitch, -89, 89); Quaternion targetRotation = Quaternion.Euler(pitch, yaw, roll); transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // EASE }
private void WiggleLegs() { float degrees = 45; float speed = 10; bool wantsToRun = Input.GetKey(KeyCode.LeftShift); if (wantsToRun) { speed = speed * 2.5f; // if running, increase run animation speed by 2.5x } Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips negative numbers // ^^^ Both do same thing, choose one vvv // alignment = Mathf.Abs(alignment); // flips negative numbers degrees *= AnimMath.Lerp(.25f, 1, alignment); // decrease "degrees" variable when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); //leg1.localRotation = Quaternion.Euler(wave, 0, 0); //This code is now updated to allow leg rotation when turning ^^^ //leg2.localRotation = Quaternion.Euler(-wave, 0, 0); }
private void SlideBarrelsHome() { barrelLeft.localPosition = AnimMath.Slide(barrelLeft.localPosition, startPosbarrelLeft, .001f); barrelRight.localPosition = AnimMath.Slide(barrelRight.localPosition, startPosbarrelRight, .001f); barrelLeft.localRotation = AnimMath.Slide(barrelLeft.localRotation, startRotbarrelLeft, .001f); barrelRight.localRotation = AnimMath.Slide(barrelRight.localRotation, startRotbarrelRight, .001f); }
private void SlideArmsHome() { if (reloadTimer <= 0) { armL.localPosition = AnimMath.Slide(armL.localPosition, startPosArmL, 0.01f); armR.localPosition = AnimMath.Slide(armR.localPosition, startPosArmR, 0.01f); } }
private void Update() { cam.transform.LookAt(target); if (isFollowing) { cam.transform.position = AnimMath.Slide(cam.transform.position, target.position, .01f); } }
private void MovePlayer() { CollisionFlags flags = new CollisionFlags(); float h = Input.GetAxis("Horizontal"); // strafing float v = Input.GetAxis("Vertical"); // forward / backward bool wantsToRun = Input.GetKey(KeyCode.LeftShift); bool isJumpHeld = Input.GetButton("Jump"); bool onJumpPress = Input.GetButtonDown("Jump"); bool isTryingToMove = (h != 0 || v != 0); if (isTryingToMove) { // turn to face the correct direction... float camYaw = cam.transform.eulerAngles.y; transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(0, camYaw, 0), .02f); } inputDirection = transform.forward * v + transform.right * h; if (inputDirection.sqrMagnitude > 1) { inputDirection.Normalize(); } //applies gravity verticalVelocity += gravityMultiplier * Time.deltaTime; // adds lateral movement to vertical movement Vector3 moveDelta = inputDirection * walkSpeed + verticalVelocity * Vector3.down; // move player if (wantsToRun) // If holding shift... { flags = pawn.Move(moveDelta * Time.deltaTime * 2.5f); // ...move player at 2.5x speed... } else { flags = pawn.Move(moveDelta * Time.deltaTime); // ...otherwise move player at 1x speed } if (pawn.isGrounded) { verticalVelocity = 0; // on ground, zero-out vertical velocity timeLeftGrounded = .2f; } // 0000 1100 (8-bit number) if (isGrounded) { if (isJumpHeld) { verticalVelocity = -jumpImpulse; timeLeftGrounded = 0; // not on ground (leg animation fix) } } }
private void MovePlayer() { float h = Input.GetAxis("Horizontal"); // strafing? float v = Input.GetAxis("Vertical"); // forward / backward float z = Input.GetAxis("Jump"); // jump bool isJumpHeld = Input.GetButtonDown("Jump"); bool isTryingToMove = (h != 0 || v != 0); if (isTryingToMove) { float camYaw = cam.transform.eulerAngles.y; transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(0, camYaw, 0), 0.02f); } inputDirection = transform.forward * v + transform.right * h; if (inputDirection.sqrMagnitude > 1) { inputDirection.Normalize(); } // apply gravity verticalVelocity += gravityMult * Time.deltaTime; // sprinting if (Input.GetKey(KeyCode.LeftShift)) { walkSpeed = 10; } else { walkSpeed = 5; } // adds lateral movement to vertical movement Vector3 moveDelta = inputDirection * walkSpeed + verticalVelocity * Vector3.down; // move pawn pawn.Move(moveDelta * Time.deltaTime); if (pawn.isGrounded) { verticalVelocity = 0; timeLeftGrounded = 0.2f; } if (isGrounded) { if (z != 0 && isJumpHeld) { verticalVelocity = -jumpImpulse; timeLeftGrounded = 0; } } }
private void ZoomCamera() { float dis = 10; if (IsTargeting()) { dis = 3; } cam.transform.localPosition = AnimMath.Slide(cam.transform.localPosition, new Vector3(0, 0, -dis), .001f); }