void Attack_SuperUpdate() { if (!IsGrounded(0.5f, true)) { currentState = GoombaStates.Fall; return; } if (Attack(8.0f)) { currentState = GoombaStates.Alert; return; } Vector3 direction = target.position - transform.position; direction = Math3d.ProjectVectorOnPlane(controller.up, direction); float distance = Vector3.Distance(target.position, transform.position); if (distance > MaintainSightDistance) { currentState = GoombaStates.Wander; return; } if (Vector3.Angle(direction, lookDirection) < FieldOfView) { lastSeenTime = Time.time; } if (SuperMath.Timer(lastSeenTime, ResumeWanderTime)) { currentState = GoombaStates.Wander; return; } lookDirection = Vector3.RotateTowards(lookDirection, direction, 70 * Mathf.Deg2Rad * Time.deltaTime, 0); moveSpeed = Mathf.MoveTowards(moveSpeed, AttackSpeed, 5.0f * Time.deltaTime); moveDirection = lookDirection * moveSpeed; }
public void TestGetFactors() { List <int> factors = SuperMath.GetFactors(6); Assert.AreEqual(2, factors.Count); Assert.AreEqual(2, factors[0]); Assert.AreEqual(3, factors[1]); factors = SuperMath.GetFactors(10); Assert.AreEqual(2, factors.Count); Assert.AreEqual(2, factors[0]); Assert.AreEqual(5, factors[1]); factors = SuperMath.GetFactors(9); Assert.AreEqual(2, factors.Count); Assert.AreEqual(2, factors.FindAll(x => x == 3).Count); factors = SuperMath.GetFactors(8); Assert.AreEqual(3, factors.Count); Assert.AreEqual(3, factors.FindAll(x => x == 2).Count); }
void Update() { print(currentRed); //Instantiate(Appear,new Vector3(59,3,67), Quaternion.identity); if (currentCoins >= GoldMarioCoinAmount && redCoinStarCount == 0) { Instantiate(Appear, new Vector3(59, 3, 67), Quaternion.Euler(new Vector3(270, 90, 90))); SoundSource.PlayOneShot(StarAppear); redCoinStarCount += 1; } if (currentRed == 8) { Instantiate(Appear, new Vector3(57, 10.26f, 21.15f), Quaternion.Euler(new Vector3(270, 90, 90))); SoundSource.PlayOneShot(StarAppear); currentRed++; } if (inputManager.PauseDown()) { if (paused) { Unpause(); } else { Pause(); } } if ((float)MusicSource.timeSamples / (float)MusicSource.clip.frequency > 140.7f) { MusicSource.timeSamples = (int)(72.775f * MusicSource.clip.frequency); } if (DebugGUI && SuperMath.Timer(lastFrameRateUpdate, 0.25f)) { lastFrameRateUpdate = Time.time; FramerateText.text = (1.0f / Time.deltaTime).ToString("F0"); } }
void Update() { if (Hovered || animating) { HoverParticles.enableEmission = true; transform.localScale = Vector3.MoveTowards(transform.localScale, initialScale * ScaleAmount, ScaleAmount / ScaleTime * Time.deltaTime); currentRotation = SuperMath.ClampAngle(currentRotation + RotationSpeed * Time.deltaTime); } else { HoverParticles.enableEmission = false; transform.localScale = Vector3.MoveTowards(transform.localScale, initialScale, ScaleAmount / ScaleTime * Time.deltaTime); if (currentRotation != 0) { currentRotation = Mathf.MoveTowards(currentRotation, 360.0f, RotationSpeed * Time.deltaTime); } } transform.rotation = Quaternion.AngleAxis(currentRotation, Vector3.down); }
void FixedUpdate() { if (Mathf.Abs(currentRotation) > MaxTilt - TiltSlowBarrier && Mathf.Sign(currentSpeed) == Mathf.Sign(currentRotation)) { currentSpeed = Mathf.MoveTowards(currentSpeed, 0, TiltDecceleration * Time.fixedDeltaTime); } if (Mathf.Abs(currentRotation) > MaxTilt && Mathf.Sign(currentSpeed) == Mathf.Sign(currentRotation)) { currentSpeed = 0; currentRotation = MaxTilt * Mathf.Sign(currentRotation); GetComponent <AudioSource>().Stop(); } if (currentRotation != 0 && SuperMath.Timer(lastTiltTime, tiltSlowTime)) { var lerpValue = Mathf.InverseLerp(0, TiltSlowBarrier * Mathf.Sign(currentRotation), currentRotation); var tiltSpeed = Mathf.Lerp(0, TiltSpeed, lerpValue); currentSpeed = Mathf.MoveTowards(currentSpeed, tiltSpeed * -Mathf.Sign(currentRotation), TiltDecceleration * Time.fixedDeltaTime); if (Mathf.Abs(currentRotation) < 0.1f) { currentRotation = 0; } } if (currentRotation == 0) { GetComponent <AudioSource>().Stop(); } currentRotation += currentSpeed * Time.fixedDeltaTime; Bridge.rotation = Quaternion.AngleAxis(currentRotation, Bridge.right) * initialRotation; }
void LateUpdate() { var height = Mathf.Lerp(MinHeight, MaxHeight, currentCameraPosition); var maxHeight = Mathf.Lerp(MinMaximumJumpHeight, MaxMaximumJumpHeight, currentCameraPosition); var maxHeightAdjustment = Mathf.Lerp(MinMaxHeightAdjustment, MaxMaxHeightAdjustment, currentCameraPosition); var distance = Mathf.Lerp(MinDistance, MaxDistance, currentCameraPosition); var angle = Mathf.Lerp(MinAngle, MaxAngle, currentCameraPosition); var weight = Mathf.Lerp(MinDampWeight, MaxDampWeight, currentCameraPosition); Vector3 targetPoint = target.position; if (mario.StateCompare(MarioMachine.MarioStates.Hang) || mario.StateCompare(MarioMachine.MarioStates.Climb)) { targetPoint = mario.ClimbTarget(); if (!planarDamping) { SetPlanarDamping(true); } } else { if (planarDamping) { SetPlanarDamping(false); } } if (!mario.Airborn()) { liftoffPoint = targetPoint; verticalPosition = Vector3.SmoothDamp(verticalPosition, Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint + height * controller.up), ref currentDampVelocity, 0.2f); currentRotationVertical = Mathf.SmoothDamp(currentRotationVertical, 0, ref currentRotationVelocity, 0.2f); } else { Vector3 groundPosition = Math3d.ProjectPointOnLine(Vector3.zero, controller.up, liftoffPoint); Vector3 airPosition = Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint); float jumpHeight = Vector3.Distance(groundPosition, airPosition); var dropRotation = Mathf.Lerp(MinDropRotation, MaxDropRotation, Mathf.InverseLerp(MinDropDistance, MaxDropDistance, jumpHeight)); if (SuperMath.PointAbovePlane(controller.up, liftoffPoint, targetPoint)) { float extraJumpHeight = 0; if (jumpHeight > maxHeight) { extraJumpHeight = Mathf.Clamp(jumpHeight - maxHeight, 0, maxHeightAdjustment); } verticalPosition = Vector3.SmoothDamp(verticalPosition, groundPosition + controller.up * ((jumpHeight * weight) + height + extraJumpHeight), ref currentDampVelocity, 0.1f); } else if (SuperMath.PointAbovePlane(controller.up, liftoffPoint - controller.up * MinDropDistance, targetPoint)) { verticalPosition = Vector3.SmoothDamp(verticalPosition, Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint + height * controller.up), ref currentDampVelocity, 0.1f); } else { currentRotationVertical = Mathf.SmoothDamp(currentRotationVertical, dropRotation, ref currentRotationVelocity, 0.5f); } } Vector3 direction = Math3d.ProjectVectorOnPlane(controller.up, (targetPoint - transform.position).normalized); float angleAdjustment = Vector3.Angle(direction, Math3d.ProjectVectorOnPlane(controller.up, transform.forward)); if (!AutoTrack) { angleAdjustment = 0; } angleAdjustment = SuperMath.PointAbovePlane(transform.right, transform.position, targetPoint) ? angleAdjustment : -angleAdjustment; currentRotationHorizontal = SuperMath.ClampAngle(currentRotationHorizontal - input.Current.CameraInput.x * XSensitivity + angleAdjustment); transform.rotation = Quaternion.AngleAxis(currentRotationHorizontal, controller.up); currentCameraPosition = Mathf.Clamp(currentCameraPosition - input.Current.CameraInput.y * YSensitivity, 0, 1); if (planarDamping) { planarPosition = Vector3.SmoothDamp(planarPosition, Math3d.ProjectPointOnPlane(controller.up, Vector3.zero, targetPoint), ref planarDampVelocity, 0.2f); } else { planarPosition = Math3d.ProjectPointOnPlane(controller.up, Vector3.zero, targetPoint); } transform.position = planarPosition + verticalPosition - transform.forward * distance + cameraShakePosition + constantShakePosition; transform.rotation = Quaternion.AngleAxis(angle + currentRotationVertical, transform.right) * transform.rotation; currentShakeMagnitude = 0; }
// public void starCollect(int ID){ // if (currentStarID == 0){ // AddStar (); // starCollected [currentStarID] = ID; // currentStarID ++; // } else { // for (int i = 0; i < scanLength; i++) { // if (ID == starCollected [i]) { // AddCollectedStar (); // starAction = true; // print ("detected"); // } // } // if (!starAction) { // AddStar (); // starAction = true;s // } // } // } void Update() { starTextHandler.UpdateValue(currentStars); livesTextHandler.UpdateValue(currentLives); if (!wf && !ps) { if (GameObject.FindObjectOfType <MarioMachine> ().transform.position.y <= -10 && overed == 0) { GameOver(); overed++; } } else if (wf && !ps) { if (GameObject.FindObjectOfType <MarioMachine> ().transform.position.y <= -10 && overed == 0) { GameOver(); overed++; } } else if (ps) { if (GameObject.FindObjectOfType <MarioMachine> ().transform.position.y <= 0 && overed == 0) { GameOver(); overed++; } } if (currentCoins >= GoldMarioCoinAmount && redCoinStarCount == 0) { //AppearCoin.SetActive(true); AppearCoinRender.enabled = true; Instantiate(AppearCoin, new Vector3(MarioTransform.position.x, MarioTransform.position.y + 2.2f, MarioTransform.position.z), Quaternion.Euler(new Vector3(270, 90, 90))); if (redCoinStarCount == 0) { SoundSource.PlayOneShot(StarAppear); } redCoinStarCount += 1; } if (currentRed == 8) { // Instantiate(Appear, new Vector3(57, 10.26f, 21.15f), Quaternion.Euler(new Vector3(270, 90, 90))); AppearRed.SetActive(true); SoundSource.PlayOneShot(StarAppear); currentRed++; } //print (wf); if (currentRing == 5) { //AppearRing.SetActive (true); Instantiate(Appear, new Vector3(50.7f, 15, -12.65f), Quaternion.Euler(new Vector3(270, 90, 90))); SoundSource.PlayOneShot(StarAppear); currentRing++; } if (enterCastle == true) { if (enterPlay == 0) { SoundSource.PlayOneShot(enterSound); enterPlay++; } MarioIn.enabled = false; TeleportToInsideCastle(); //ExitToMainMenu (); } if (exitCastle == true) { if (enterPlay == 0) { SoundSource.PlayOneShot(enterSound); enterPlay++; } MarioIn.enabled = false; TeleportToOutsideCastle(); //ExitToMainMenu (); } if (bobOmbEnter == true) { if (enterPlay == 0) { SoundSource.PlayOneShot(enterSound); enterPlay++; } MarioIn.enabled = false; TeleportToBobombBattlefield(); GameObject.FindObjectOfType <MarioVerySmartCamera>().canMove = false; } if (whompsEnter == true) { if (enterPlay == 0) { SoundSource.PlayOneShot(enterSound); enterPlay++; } MarioIn.enabled = false; TeleportToWhompsFortress(); GameObject.FindObjectOfType <MarioVerySmartCamera>().canMove = false; } if (inputManager.PauseDown() && pausable == true) { if (paused) { Unpause(); } else { Pause(); } } if ((float)MusicSource.timeSamples / (float)MusicSource.clip.frequency > 140.7f) { MusicSource.timeSamples = (int)(72.775f * MusicSource.clip.frequency); } if (DebugGUI && SuperMath.Timer(lastFrameRateUpdate, 0.25f)) { lastFrameRateUpdate = Time.time; FramerateText.text = (1.0f / Time.deltaTime).ToString("F0"); } for (int i = 0; i < scanLength; i++) { starCollected[i] = stats.deadStars[i]; } }
void Bounce(float height) { moveDirection += SuperMath.CalculateJumpSpeed(height, Gravity) * Vector3.up; }