static private IEnumerator Simulate(Transform inTransform, Runtime inRuntime) { Vector3 currentEuler = inTransform.GetRotation(Axis.XYZ, inRuntime.Space); Vector3 deltaEuler; float dt, dt2, damp; while (inRuntime.Duration > 0) { dt = Routine.DeltaTime; dt2 = dt * dt; damp = inRuntime.Damping == 0 ? 1 : TweenUtil.LerpDecay(inRuntime.Damping, 1, dt); deltaEuler.x = deltaEuler.y = deltaEuler.z = 0; VectorUtil.Add(ref deltaEuler, inRuntime.Velocity, dt); VectorUtil.Add(ref deltaEuler, inRuntime.Acceleration, 0.5f * dt2); VectorUtil.Add(ref currentEuler, deltaEuler); inTransform.SetRotation(currentEuler, Axis.XYZ, inRuntime.Space); VectorUtil.Add(ref inRuntime.Velocity, inRuntime.Acceleration, dt); VectorUtil.Multiply(ref inRuntime.Velocity, damp); inRuntime.Duration -= dt; if (inRuntime.Callback != null) { inRuntime.Callback(inTransform, currentEuler, inRuntime.Velocity); } yield return(null); } }
static private IEnumerator SimulateAnchorPos(RectTransform inTransform, Runtime inRuntime) { Vector3 currentPos; Vector3 deltaPos; float dt, dt2, damp; while (inRuntime.Duration > 0) { dt = Routine.DeltaTime; dt2 = dt * dt; damp = inRuntime.Damping == 0 ? 1 : TweenUtil.LerpDecay(inRuntime.Damping, 1, dt); deltaPos.x = deltaPos.y = deltaPos.z = 0; VectorUtil.Add(ref deltaPos, inRuntime.Velocity, dt); VectorUtil.Add(ref deltaPos, inRuntime.Acceleration, 0.5f * dt2); VectorUtil.Add(ref deltaPos, inRuntime.Gravity, 0.5f * dt2); currentPos = inTransform.anchoredPosition3D; VectorUtil.Add(ref currentPos, deltaPos); inTransform.anchoredPosition3D = currentPos; VectorUtil.Add(ref inRuntime.Velocity, inRuntime.Acceleration, dt); VectorUtil.Add(ref inRuntime.Velocity, inRuntime.Gravity, dt); VectorUtil.Multiply(ref inRuntime.Velocity, damp); inRuntime.Duration -= dt; if (inRuntime.Callback != null) { inRuntime.Callback(inTransform, currentPos, inRuntime.Velocity); } yield return(null); } }
public void FixedUpdate() { if (pressed) { GameObject[] robots = GameObject.FindGameObjectsWithTag("Robot"); float robotX0 = robots[0].GetComponent <Robot>().transform.position.x; float robotX1 = robots[1].GetComponent <Robot>().transform.position.x; if (Mathf.Abs(robotX0 - robotX1) < 45 && ((bodyToMove.leftFacing && left) || (!bodyToMove.leftFacing && !left))) { //too close and moving closer return; } if ((Camera.main.WorldToViewportPoint(bodyToMove.transform.position).x < .8f && left) || (Camera.main.WorldToViewportPoint(bodyToMove.transform.position).x > 1.5f && !left)) { return; } bodyToMove.transform.position = VectorUtil.Add(bodyToMove.transform.position, x: (left ? -1 : 1) * moveAmount); } }
// returns cells' WORLD coordinates if the tetramino was moved by offset & rotated according to rotation type public Vector2Int[] GetAbsPoses(Vector2Int offset, Tetramino.RotationType rotation) { Vector2Int[] rotated = RotateArray(Poses, rotationPoint, rotation); return(VectorUtil.Add(rotated, centerPos + offset)); }