public override void Update() { var normalAngle = currentAngle + (isClockWise ? -90f : 90f); var mouseVector = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")) * (MicrogameTimer.instance.beatsLeft > maxBeatsLeftForInput ? 0f : 1f); var projection = Vector3.Project(mouseVector, MathHelper.getVector2FromAngle(normalAngle, 1f)); if (MathHelper.Approximately( MathHelper.trueMod(((Vector2)projection).getAngle(), 360f), MathHelper.trueMod(normalAngle, 360f), 1f)) { currentAngle += projection.magnitude * power * (isClockWise ? -1f : 1f); Debug.DrawLine(transform.position, transform.position + projection); } else { Debug.DrawLine(transform.position, transform.position + projection, Color.red); } transform.localPosition = MathHelper.getVector2FromAngle(currentAngle, radius); var angleProgress = (currentAngle - 270f) * (isClockWise ? -1f : 1f); progress = angleProgress * angleProgressMult; if (angleProgress > anglePerNote * (notesPlayed + 1)) { notePlayer.PlayNote(); notesPlayed++; } }
public static Direction FromVector(Vector3 vector) { if (MathHelper.Approximately(vector, Vector3.back)) { return(Direction.Backward); } if (MathHelper.Approximately(vector, Vector3.forward)) { return(Direction.Forward); } if (MathHelper.Approximately(vector, Vector3.left)) { return(Direction.Left); } if (MathHelper.Approximately(vector, Vector3.right)) { return(Direction.Right); } if (MathHelper.Approximately(vector, Vector3.up)) { return(Direction.Up); } if (MathHelper.Approximately(vector, Vector3.down)) { return(Direction.Down); } throw new InvalidOperationException("No direction for this vector"); }
void updateWalkSpeed(int direction, bool grounded) { Vector2 velocity = _rigidBody2D.velocity; float goalSpeed, acc; goalSpeed = (float)direction * (grounded ? walkSpeed : jumpMoveSpeed); if (grounded || Mathf.Abs(velocity.x) > jumpMoveSpeed) { acc = (direction == 0f) ? walkDec : walkAcc; } else { acc = (direction == 0f) ? jumpDec : jumpAcc; } if (isTurningAround(direction)) { acc *= 2f; } if (!MathHelper.Approximately(velocity.x, goalSpeed, .0001f)) { float diff = acc * Time.deltaTime; if (Mathf.Abs(goalSpeed - velocity.x) <= diff) { _rigidBody2D.velocity = new Vector2(goalSpeed, velocity.y); } else { _rigidBody2D.velocity = new Vector2(velocity.x + (diff * Mathf.Sign(goalSpeed - velocity.x)), velocity.y); } } }
void forceResolutionAspect() { int height = Screen.currentResolution.height; if (!MathHelper.Approximately((float)height, (float)Screen.currentResolution.width * 3f / 4f, .01f)) { Screen.SetResolution((int)((float)Screen.currentResolution.width * 3f / 4f), height, Screen.fullScreen); } }
void Update() { if (!isTray && onTray) { //Snap to goal Y (for when food is taken away) if (!MathHelper.Approximately(transform.localPosition.y, GoalY, .001f)) { transform.moveTowardsLocal2D(GoalPosition, yLerpSpeed); } } }
public virtual void Zoom(float deltaZ, Quaternion rotation, float epsilonSq) { if (m_lockInput) { return; } if (!CanZoom) { deltaZ = 0; } Camera camera = Window.Camera; if (camera.orthographic) { camera.orthographicSize -= deltaZ * camera.orthographicSize; if (camera.orthographicSize < 0.01f) { camera.orthographicSize = 0.01f; } if (ChangeOrthographicSizeOnly) { return; } } Vector3 fwd = (rotation * Vector3.forward) * deltaZ; if (m_constantZoomSpeed) { fwd *= m_zoomSpeed; } else { fwd *= Mathf.Max(m_zoomSpeed, Mathf.Abs(m_orbitDistance)); } Transform cameraTransform = Window.Camera.transform; m_orbitDistance = m_orbitDistance - fwd.z; fwd.z = 0; Vector3 negDistance = new Vector3(0.0f, 0.0f, -m_orbitDistance); m_targetPosition = cameraTransform.TransformVector(fwd) + cameraTransform.rotation * negDistance + PivotTransform.position; if (!MathHelper.Approximately(m_targetPosition, cameraTransform.position, epsilonSq)) { cameraTransform.position = m_targetPosition; } }
void Update() { //var timeSinceLaunch = (timingData.PreciseBeat - target.LaunchBeat) * timingData.BeatDuration; //var simulatedTimeSinceLaunch = Time.time - simulatedLaunchedTime; var goalNormalizedTime = (timingData.PreciseBeat - target.LaunchBeat) / 4f; var normalizedTime = rigAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime; if (!MathHelper.Approximately(normalizedTime, goalNormalizedTime, syncBufferNormalizedTime)) { rigAnimator.Rebind(); rigAnimator.Play("Launch", 0, goalNormalizedTime); print("Correcting animator"); } }
public static object DefaultReader() { StringBuilder sb = new StringBuilder(); bool forceread = false; while (inputInd < inputStr.Length) { char c = Read(); if (c == '\r') { continue; } if (!forceread && char.IsWhiteSpace(c)) { break; } if (!forceread && c == '\\') { forceread = true; } else { forceread = false; sb.Append(c); //if(context.GetModifier(pointer.position.x, pointer.position.y) == '͍') { // break; //} } } double d; string s = sb.ToString(); if (double.TryParse(s, out d)) { if (MathHelper.Approximately((float)d, (int)d)) { return((int)d); } return(d); } else if (sb.Length > 1) { return(s); } else if (sb.Length > 0) { return(s[0]); } return(null); }
void addCurrentResolutionIfNeeded(List <Resolution> resolutions) { Resolution currentResolution = Screen.currentResolution; int resolutionCheckThreshold = 3; foreach (Resolution resolution in resolutions) { if (MathHelper.Approximately(resolution.width, currentResolution.width, resolutionCheckThreshold) && MathHelper.Approximately(resolution.height, currentResolution.height, resolutionCheckThreshold)) { return; } } resolutions.Add(currentResolution); }
float getZIndexMult() { float degrees = transform.rotation.eulerAngles.y % 360; bool flip = degrees > 90 && degrees < 270; if (MathHelper.Approximately(degrees, 0f, .1f) || MathHelper.Approximately(degrees, 180f, .1f)) { return(flip ? -1f : 1f); } degrees %= 180; if (degrees > 90) { degrees = 180 - degrees; } return((90 - degrees) / 90 * (flip ? -1f : 1f)); }
private void Lower() { //if ((light.transform.position - transform.position).magnitude < light.transform.localScale.x) // return; currentLowerSpeed = Mathf.MoveTowards(currentLowerSpeed, lowerSpeed, lowerAcc * Time.deltaTime); var frameLowerSpeed = currentLowerSpeed; if (killedPlayer) { frameLowerSpeed *= DarkRoomEffectAnimationController.instance.walkSpeed; } // Lower.. down if (transform.position.y <= lowY) { //transform.position = new Vector3(transform.position.x, lowY, transform.position.z); //transformThread.localScale = new Vector3(transformThread.localScale.x, highY - lowY + 1, transformThread.localScale.z); rigAnimator.SetInteger("Direction", 0); } else { transform.position += new Vector3(0f, -frameLowerSpeed, 0f) * Time.deltaTime; transformThread.localScale += new Vector3(0f, frameLowerSpeed, 0f) * Time.deltaTime; rigAnimator.SetInteger("Direction", -1); } var threadDiff = transform.position.y; transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, lowY, transform.position.z), frameLowerSpeed * Time.deltaTime); threadDiff = transform.position.y - threadDiff; transformThread.localScale -= new Vector3(0f, threadDiff, 0f); if (MathHelper.Approximately(transform.position.y, lowY, .01f)) { rigAnimator.SetInteger("Direction", 0); } else { rigAnimator.SetInteger("Direction", -1); } }
void updateRotation() { float rotation = getSpinRotation(); //Spin between 0 and -180 degrees float goalRotation = _facingRight ? -180f : 0f; if (!MathHelper.Approximately(rotation, goalRotation, .0001f)) { float diff = rotateSpeed * Time.deltaTime; if (Mathf.Abs(goalRotation - rotation) <= diff) { setSpinRotation(goalRotation); } else { setSpinRotation(rotation + (diff * Mathf.Sign(goalRotation - rotation))); } } }
public bool Execute(Pointer pointer, IRunicContext context) { object a = pointer.Pop(); object b = pointer.Pop(); if (a != null && b != null) { if (a is ValueType && b is ValueType) { if (MathHelper.IsInteger((ValueType)a) && MathHelper.IsInteger((ValueType)b)) { int c = (int)MathHelper.GetValue((ValueType)b) % (int)MathHelper.GetValue((ValueType)a); pointer.Push(c); } else { double d = MathHelper.GetValue((ValueType)a); if (MathHelper.Approximately((float)d, 0)) { pointer.DeductMana(pointer.GetMana()); return(true); } double c = MathHelper.GetValue((ValueType)b) % d; pointer.Push(c); } } else if (a is ValueType && b is string) { int c = (int)MathHelper.GetValue((ValueType)a); if (c < 0) { c = ((string)b).Length + c; } pointer.Push(((string)b)[c]); } else { } } return(true); }
/* My methods */ private void Retreat() { // Retreat up var mult = 1f - (raiseDelayTimer / raiseDelay); var threadDiff = transform.position.y; var frameSpeed = retreatSpeed; if (killedPlayer) { frameSpeed *= DarkRoomEffectAnimationController.instance.walkSpeed; } transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, highY, transform.position.z), frameSpeed * Time.deltaTime * mult); threadDiff = transform.position.y - threadDiff; transformThread.localScale -= new Vector3(0f, threadDiff, 0f); if (MathHelper.Approximately(transform.position.y, highY, .01f)) { rigAnimator.SetInteger("Direction", 0); } else { rigAnimator.SetInteger("Direction", 1); } if (transform.position.y >= highY) { //transform.position = new Vector3(transform.position.x, highY, transform.position.z); //transformThread.localScale = new Vector3(transformThread.localScale.x, 1, transformThread.localScale.z); rigAnimator.SetInteger("Direction", 0); } else { } currentLowerSpeed = 0f; }
void updateMovement() { transform.position = getMousePosition(); //going nowhere if (MathHelper.Approximately(lastMousePosition.x, transform.position.x, .0001f)) { setFacingRight(isFacingRight()); } //going left else if (lastMousePosition.x > transform.position.x) { setFacingRight(false); } //going right else { setFacingRight(true); } float speed = (transform.position.x - lastMousePosition.x) / Time.deltaTime; if (!MathHelper.Approximately(speed, 0f, .01f)) { joint.useMotor = true; JointMotor2D motor = joint.motor; motor.motorSpeed = speed * motorSpeedMult; joint.motor = motor; } else { joint.useMotor = false; } lastMousePosition = getMousePosition(); }
void updateMovement() { transform.position = getMousePosition(); //going nowhere if (MathHelper.Approximately(lastMousePosition.x, transform.position.x, .0001f)) { setFacingRight(isFacingRight()); } //going left else if (lastMousePosition.x > transform.position.x) { setFacingRight(false); } //going right else { setFacingRight(true); } //updateBodyRotation(); }
private void LateUpdate() { if (isFrozen) { return; } Vector3 targetPosition = World.Current.Player.transform.position + new Vector3(0, 0, -10); if (lerpToPosition) { targetPosition.z = transform.position.z; transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, dampTime); if (MathHelper.Approximately(transform.position, targetPosition)) { lerpToPosition = false; } return; } Camera.main.transform.position = targetPosition; }
public bool Execute(Pointer pointer, IRunicContext context) { object a = pointer.Pop(); object b = pointer.Pop(); if (a != null && b != null) { if (a is ValueType && b is ValueType) { if (MathHelper.IsInteger((ValueType)a) && MathHelper.IsInteger((ValueType)b)) { float c = (float)MathHelper.GetValue((ValueType)b) / (int)MathHelper.GetValue((ValueType)a); pointer.Push(c); } else if (a is Vector3 || b is Vector3) { if (a is Vector3 && b is Vector3) { pointer.Push(Vector3.Dot((Vector3)a, (Vector3)b)); } else if (a is Vector3) { double d = MathHelper.GetValue((ValueType)b); if (MathHelper.Approximately((float)d, 0)) { pointer.DeductMana(pointer.GetMana()); return(true); } pointer.Push(((Vector3)a) / (float)d); } else if (b is Vector3) { double d = MathHelper.GetValue((ValueType)a); if (MathHelper.Approximately((float)d, 0)) { pointer.DeductMana(pointer.GetMana()); return(true); } pointer.Push(((Vector3)b) / (float)d); } } else { double d = MathHelper.GetValue((ValueType)a); if (MathHelper.Approximately((float)d, 0)) { pointer.DeductMana(pointer.GetMana()); return(true); } double c = MathHelper.GetValue((ValueType)b) / d; pointer.Push(c); } } else if (a is ValueType && b is string) { string s = (string)b; int n = (int)MathHelper.GetValue((ValueType)a); int m = 0; int r = 0; if (n < 0) { n *= -1; m = (int)(System.Math.Ceiling((float)s.Length / n) * n); r = m - s.Length; s = s.PadLeft(m); } bool b2 = true; foreach (string chk in s.ChunksUpto(n)) { if (b2 && r > 0) { string chk2 = chk.Substring(r); b2 = false; pointer.Push(chk2); } else { pointer.Push(chk); } } } else { } } return(true); }
void Update() { if (startTime > 0f) { startTime -= Time.deltaTime; if (startTime <= 0f) { body.isKinematic = false; coinCollider.enabled = true; startTime = 0f; } } else if (transform.position.y <= slowHeight && transform.position.y > fallHeight) { body.velocity = Vector2.down * speed; } else if (transform.position.y <= fallHeight) { body.velocity = Vector2.down * speed * 3f; } else { body.AddTorque(-body.velocity.x); } float zeroThreshold = .01f; if (!body.isKinematic && MathHelper.Approximately(Mathf.Abs(body.velocity.x) + Mathf.Abs(body.velocity.y), 0f, zeroThreshold)) { zeroTime += Time.deltaTime; if (zeroTime >= ZeroTimer && lastTouchedNeighbor != null) { Physics2D.IgnoreCollision(coinCollider, lastTouchedNeighbor); zeroTime = 0f; } } else { zeroTime = 0f; } if (body.velocity.y > 0f && lastVelocity.y <= 0f) { playBounceSound(body.velocity.y); } if ((body.velocity.x < 0f && body.velocity.x > 0f) || (body.velocity.x > 0f && body.velocity.x < 0f)) { playBounceSound(body.velocity.x); } lastVelocity = body.velocity; if (!outOfPlay && transform.position.y < outOfPlayY) { outOfPlay = true; DonationReimu.coinsInPlay--; } }
void Update() { // Is this the ice cream? if (_tile[cirnoGridX, cirnoGridY] == "B" && MathHelper.Approximately(transform.position.x, cirnoEndPos.x, .01f) && MathHelper.Approximately(transform.position.y, cirnoEndPos.y, .01f)) { if (!hasWon) { Win(); hasWon = true; tiltDirection = 0f; } } // Update angle currentAngle = Mathf.MoveTowards(currentAngle, getTiltAngleGoal(), tiltSpeed * Time.deltaTime); tiltPivot.eulerAngles = Vector3.forward * currentAngle; // Is this a Waka passing? int wakaIndex; if (int.TryParse(_tile[cirnoGridX, cirnoGridY], out wakaIndex)) { // Is Waka passing through? GameObject waka = IcePath_GenerateMap.wakaObject[wakaIndex]; IcePath_Waka wakaScript = waka.GetComponent <IcePath_Waka>(); if (!wakaScript.isPassable) { if (!isHit) { // Get hit Die(); isHit = true; MicrogameController.instance.playSFX(hitSound, volume: 0.75f, panStereo: AudioHelper.getAudioPan(transform.position.x)); MicrogameController.instance.setVictory(victory: false, final: true); } } } // Has Cirno been hit? if (isHit) { // Lose condition - fly away now transform.position = transform.position + (new Vector3(-8, 8, 0) * Time.deltaTime); transform.Find("Spin Pivot").Find("Rig").Rotate(new Vector3(0, 0, 270 * Time.deltaTime)); } else // Has Cirno won? if (hasWon) { /* oh. she has? alright */ } else // Move on as usual { // Move Cirno towards grid if applicable MathHelper.moveTowards2D(transform, cirnoEndPos, moveSpeed); // Movement int moveX = (Input.GetKeyDown(KeyCode.RightArrow) ? 1 : 0) - (Input.GetKeyDown(KeyCode.LeftArrow) ? 1 : 0); int moveY = (Input.GetKeyDown(KeyCode.UpArrow) ? 1 : 0) - (Input.GetKeyDown(KeyCode.DownArrow) ? 1 : 0); if (moveX != 0) { moveY = 0; } else { moveX = 0; } // Player is moving if (moveX != 0 || moveY != 0) { // Valid movement? if (canWalkInto(cirnoGridX + moveX, cirnoGridY - moveY)) { cirnoGridX += moveX; cirnoGridY -= moveY; transform.position = cirnoEndPos; //Snap to next block cirnoEndPos = mapPos(cirnoGridX, -cirnoGridY); MicrogameController.instance.playSFX(moveClip, pitchMult: Random.Range(.96f, 1.04f), panStereo: AudioHelper.getAudioPan(transform.position.x), volume: .5f); tiltDirection = tiltDirection == 0f ? -1f : -tiltDirection; if (moveX != 0 && (float)moveX != Mathf.Sign(tiltPivot.localScale.x)) { tiltPivot.localScale = new Vector3(-tiltPivot.localScale.x, tiltPivot.localScale.y, tiltPivot.localScale.z); } } } } }
void Start() { _facingRight = MathHelper.Approximately(getSpinRotation(), -180f, 1f); }
public static bool operator !=(Vector3 a, Vector3 b) { return(!(MathHelper.Approximately(a.x, b.x) && MathHelper.Approximately(a.y, b.y) && MathHelper.Approximately(a.z, b.z))); }
public void FreeMove(Vector2 rotate, Vector3 move, float forward) { if (m_lockInput || !CanFreeMove) { return; } Transform camTransform = Window.Camera.transform; if (m_rotationInvertY) { rotate.y = -rotate.y; } if (m_rotationInvertX) { rotate.x = -rotate.x; } m_targetRotation = Quaternion.Inverse( Quaternion.Euler(rotate.y, 0, 0) * Quaternion.Inverse(m_targetRotation) * Quaternion.Euler(0, -rotate.x, 0)); if (m_freeRotationSmoothSpeed <= 0) { camTransform.rotation = m_targetRotation; } else { if (!MathHelper.Approximately(camTransform.rotation, m_targetRotation)) { camTransform.rotation = Quaternion.Slerp( camTransform.rotation, m_targetRotation, m_freeRotationSmoothSpeed * Time.deltaTime); } } Vector3 zoomOffset = Vector3.zero; if (Window.Camera.orthographic) { if (Mathf.Approximately(move.y, 0)) { move.y = forward; } else { move.y /= 10.0f; } if (!Mathf.Approximately(move.y, 0)) { Vector3 position = camTransform.position; Zoom(move.y, Quaternion.identity); zoomOffset = camTransform.position - position; camTransform.position = position; move.y = 0; } } else { if (Mathf.Approximately(move.y, 0)) { move.y = forward * 50; } } m_targetPosition = m_targetPosition + zoomOffset + camTransform.forward * move.y + camTransform.right * move.x + camTransform.up * move.z; if (m_freeMovementSmoothSpeed <= 0) { camTransform.position = m_targetPosition; } else { if (!MathHelper.Approximately(m_targetPosition, camTransform.position)) { Vector3 newPosition = Vector3.Lerp( camTransform.position, m_targetPosition, m_freeMovementSmoothSpeed * Time.deltaTime); camTransform.position = newPosition; } } Vector3 newPivot = camTransform.position + camTransform.forward * m_orbitDistance; SecondaryPivotTransform.position += newPivot - Pivot; PivotTransform.position = newPivot; }