// Walk horizontaly
        public override void WalkHorizontal(float targetSpeed)
        {
            // lerp the sprite scale (prob wont keep)
            imageScale = MyMaths.Lerp(imageScale,
                                      Math.Sign(targetSpeed),
                                      .25f * GahameController.GameSpeed * (GameInput.ControllerMode && !GahameController.CutScene ? Math.Abs(GameInput.AbsLeftStickX) : 1));

            // keeps it from memeing maxSpeed
            targetSpeed = MyMaths.Clamp(targetSpeed, -maxSpeed, maxSpeed);

            // Approach the target speed
            physics.Velocity.X = MyMaths.Approach(physics.Velocity.X, targetSpeed,
                                                  GahameController.GameSpeed * (physics.Grounded ? accelerationSpeed : airAccelerationSpeed));

            // Sprite things
            if (spriteManager.CurrentSprite != "Moving")
            {
                spriteManager.ChangeSprite("Moving");
                spriteManager.GetSprite("Moving").CurrentImage = 0;
            }
            spriteManager.GetSprite("Moving").ImageSpeed = .1f * Math.Abs(physics.Velocity.X / maxSpeed);

            // You be walking
            WalkingHorizontal = true;
        }
    float getPredictionOfWindDirection()
    {
        PredictResponse predictedDirSin = api.GetPrediction(zoneId, "sin wind direction");

        Debug.Log("prediction = " + predictedDirSin.ToString());
        DateTime sinAge = Convert.ToDateTime(predictedDirSin.latestDataUsed);


        Debug.Log("prediction age  = " + predictionAge.ToString() + " - " + (DateTime.Now.Second - predictionAge.Second).ToString());

        PredictResponse predictedDirCos = api.GetPrediction(zoneId, "cos wind direction");

        Debug.Log("prediction = " + predictedDirCos.ToString());
        DateTime cosAge = Convert.ToDateTime(predictedDirCos.latestDataUsed);

        Debug.Log("prediction age  = " + predictionAge.ToString() + " - " + (DateTime.Now.Second - predictionAge.Second).ToString());

        if (sinAge == cosAge)
        {
            predictionAge = sinAge;
            arrow.color   = new Color(1f, 1f, 0f);
        }
        else
        {
            arrow.color = new Color(1f, 1f, 1f);
        }



        return(MyMaths.SinCosToDegrees(predictedDirSin.value, predictedDirCos.value));
    }
 public StationDataCollector(int zoneId, double windSpeed, double windDirection)
 {
     this.zoneId            = zoneId;
     this.dataLables        = new string[] { "wind speed", "wind direction", "sin wind direction", "cos wind direction" };
     this.dataValues        = new double[] { windSpeed, windDirection, Math.Sin(MyMaths.DegreeToRadian(windDirection)), Math.Cos(MyMaths.DegreeToRadian(windDirection)) };
     this.dateTimeCollected = DateTime.Now.ToString();
 }
 public ScoutDataCollector(double longitude, double latitude, double windSpeed, double windDirection)
 {
     this.longitude         = longitude;
     this.latitude          = latitude;
     this.dataLables        = new string[] { "wind speed", "wind direction", "sin wind direction", "cos wind direction" };
     this.dataValues        = new double[] { windSpeed, windDirection, Math.Sin(MyMaths.DegreeToRadian(windDirection)), Math.Cos(MyMaths.DegreeToRadian(windDirection)) };
     this.dateTimeCollected = DateTime.Now.ToString();
 }
Example #5
0
        // Walk vertically
        public override void WalkVertical(float speed)
        {
            // Approach the speed
            physics.Velocity.Y = MyMaths.Approach(physics.Velocity.Y, speed, accelerationSpeed * GahameController.GameSpeed);
            WalkingVertical    = true;

            direction.X = 0;
            direction.Y = Math.Sign(speed);
        }
Example #6
0
    // X,0,Z
    public Triangulator(Vector3[] points3d)
    {
        Vector2[] points = new Vector2[points3d.Length];
        for (var i = 0; i < points3d.Length; i++)
        {
            points[i] = MyMaths.squashVector(points3d[i]);
        }

        m_points = new List <Vector2>(points);
    }
Example #7
0
    public void setStreetRender(float width, float direction)
    {
        float result = MyMaths.Remap(direction, 0, 360, 360, 0);

        transform.localEulerAngles = new Vector3(0, 0, result);

        float scale = (width / 50.0f) + 0.2f;

        transform.localScale = new Vector3(scale, 0.5f, 1f);
    }
Example #8
0
    private void CalculateNumberOfinstatiates()
    {
        Vector3 temp = ((max - min) / sizeOfSprite) + Vector3.one * offset;

        temp = MyMaths.Vector_Ceil(temp);
        for (int i = 0; i < 3; i++)
        {
            NumberOfInstatiates[i] = MyMaths.Magnitude(temp[i]);
        }
    }
    /*	using global wind condition object to calculate wind direction within street
     *      street width is in range of 0.04 - 0.14
     */
    static float CalculateStreetWindDirection(float gWindDir, float gWindSpeed, float streetDir, float streetWdth)
    {
        float scaledStreetWidth = 0.14f - ((0.1f / 50f) * streetWdth);

        Assert.IsTrue((scaledStreetWidth >= 0.03) && (scaledStreetWidth <= 0.15));

        float sig1 = (1f / (1f + Mathf.Pow(Mathf.Exp(1), (-(gWindDir - streetDir + 90f) * scaledStreetWidth)))) * 180f;
        float sig2 = (1f / (1f + Mathf.Pow(Mathf.Exp(1), (-(gWindDir - streetDir - 90f) * scaledStreetWidth)))) * 180f;
        float sig3 = (1f / (1f + Mathf.Pow(Mathf.Exp(1), (-(gWindDir - streetDir - 270f) * scaledStreetWidth)))) * 180f;

        return(MyMaths.mod((sig1 + sig2 + sig3 - 180f + streetDir), 360f));
    }
Example #10
0
    //Calculates the numer of prefabs which must be used in each dimention
    private static void CalculateNumberOfInstances()
    {
        Vector3 temp = (max - min) / sizeOfSprite;

        //Rounds all values inside vector up
        temp = MyMaths.Vector_Ceil(temp);
        for (int i = 0; i < 3; i++)
        {
            //Number of instances to be created must be positive
            NumberOfInstances[i] = MyMaths.Magnitude(temp[i]);
        }
    }
Example #11
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            Vector2 thicknessCorrection = new Vector2((thickness / 2) * Math.Sign(speed.Y), (thickness / 2) * -Math.Sign(speed.X));

            ShapeRenderer.DrawLine(spriteBatch, startPosition + thicknessCorrection, Position + speed + thicknessCorrection, Color.Red, thickness, .8f);

            Vector2 random = new Vector2(MyMaths.RandomInRange(-thickness / 4, thickness / 4), MyMaths.RandomInRange(-thickness / 4, thickness / 4));

            ShapeRenderer.DrawLine(spriteBatch, startPosition + random + thicknessCorrection / 3, Position + speed / 2 + random + thicknessCorrection / 3, Color.Pink, thickness / 3, .8f);

            base.Draw(spriteBatch);
        }
Example #12
0
    //Controls the zoom of the camera
    private void ControlZoom()
    {
        // 1 for positive , 0 for no input , -1 for negative input
        float input = Input.GetAxis("Mouse ScrollWheel");

        if (input != 0)
        {
            float sign = -Mathf.Sign(input);                             //minus so backwards is zoom out while inwards is zoom in
            currentZoom += sign * zoomMod;
            currentZoom  = MyMaths.Clamp(currentZoom, minZoom, maxZoom); //Clamps the currentZoom between minZoom and maxZoom
            Camera.main.orthographicSize = currentZoom;                  // Updates zoom
        }
    }
Example #13
0
 // Update
 public override void Update(GameTime gameTime)
 {
     // do the fade stuff
     alpha = MyMaths.Approach(alpha, (reverseAlpha ? 0 : 1), fadeSpeed);
     if (alpha >= 1)
     {
         reverseAlpha = true;
         ChangeScreen();
     }
     if (alpha == 0)
     {
         StopTransition();
     }
 }
Example #14
0
        // Updateroni
        public override void Update(GameTime gameTime)
        {
            // Inportant fix
            size  = new Vector2(Camera.View.X, Camera.View.Y / 4);
            size2 = new Vector2(Camera.View.X / 2, Camera.View.Y);

            // Y Position fix
            rec1.Y = 0;
            rec2.Y = size.Y;
            rec3.Y = size.Y * 2;
            rec4.Y = size.Y * 3;

            // rec 1 thing
            speed1 = MyMaths.Approach(speed1, 1, 0.95f);
            rec1.X = MyMaths.Approach(rec1.X, 0, speed1);

            // rec 2 thing
            if (rec1.X == 0)
            {
                speed4 = MyMaths.Approach(speed4, 1, 0.95f);
                rec4.X = MyMaths.Approach(rec4.X, 0, speed4);
            }

            // rec 3 and 4 ok
            if (rec4.X == 0)
            {
                speed2 = MyMaths.Approach(speed2, 1, 0.95f);
                rec2.X = MyMaths.Approach(rec2.X, 0, speed2);
                rec3.X = MyMaths.Approach(rec3.X, 0, speed2);
            }

            // rec 5 n 6
            if (rec2.X == 0)
            {
                if (!screenChanged)
                {
                    ChangeScreen();
                    screenChanged = true;
                }
                rec5.X = MyMaths.Approach(rec5.X, -size2.X, 5);
                rec6.X = MyMaths.Approach(rec6.X, size.X, 5);
            }

            // STOPIT
            if (rec6.X == size.X)
            {
                StopTransition();
            }
        }
Example #15
0
        public bool DoesIntersect(LineCollider otherLine, Vector2 p1, Vector2 p2)
        {
            float k1 = (EndPoint.Y - p1.Y) / (EndPoint.X - p1.X);
            float k2 = (otherLine.EndPoint.Y - p2.Y) / (otherLine.EndPoint.X - p2.X);

            if (k1 == k2)
            {
                return(false);
            }

            float xIntersect = (p2.Y - p1.Y) / (k1 - k2);
            float yIntersect = k1 * xIntersect + p1.Y;

            return(MyMaths.DistanceCubed(p1, EndPoint) < MyMaths.DistanceCubed(p1, new Vector2(xIntersect, yIntersect)));
        }
Example #16
0
    void Update()
    {
        float easeArrowScale = MyMaths.CubicEaseOut(Time.time - startTime, 0, targetArrowScale - initialArrowScale, durationTime);

        currentArrowScale = easeArrowScale + initialArrowScale;

        transform.localScale = new Vector3(currentArrowScale, currentArrowScale, 1f);

        easeArrowDir = MyMaths.ElasticEaseOut(Time.time - startTime, 0, targetArrowDir - initialArrowDir, durationTime);

        currentArrowDir = easeArrowDir + initialArrowDir;

        float result = MyMaths.Remap(currentArrowDir, 0, 360, 360, 0);

        transform.localEulerAngles = new Vector3(0, 0, result);
    }
Example #17
0
        public long Answer(params long[] arguments)
        {
            MyMaths mm = new MyMaths();

            for (int i = 0; i < 2000000; i++)
            {
                int tri = mm.TriangleNumber(i);
                int dev = mm.NumberOfDevisors(tri);
                if (dev > 500)
                {
                    return(tri);
                }
            }

            return(0);
        }
Example #18
0
    private Transform CreateHoleObject(List <Vector3> shapePoints)
    {
        var startIndex = 1;
        var endIndex   = shapePoints.Count - 1;

        Vector3[] vertices;
        Vector2[] uv;
        Mesh      mesh;

        var hole = Instantiate(_dynamicHolePrefab, Vector3.zero, Quaternion.identity, transform);

        hole.GetComponent <MeshFilter>().mesh = mesh = new Mesh();
        hole.gameObject.name = mesh.name = $"Hole{_holeId}";
        var num = endIndex - startIndex;

        vertices = new Vector3[num];
        uv       = new Vector2[num];

        for (int i = startIndex, k = 0; i < endIndex; i++, k++)
        {
            vertices[k] = shapePoints[i];
            uv[k]       = MyMaths.squashVector(vertices[k]);
        }

        mesh.vertices = vertices;
        mesh.uv       = uv;

        var triangulator = new Triangulator(vertices);

        mesh.triangles = triangulator.Triangulate();
        mesh.RecalculateNormals();

        var normals = mesh.normals;

        for (var i = 0; i < normals.Length; i++)
        {
            if (normals[i].normalized != Vector3.up)
            {
                // HAXXX: if you retrace your steps and finish a shape, it comes out all messed up, this kind of helps
                // Debug.Log("Fixed inverse hole");
                MyMaths.InverseTriangles(mesh);
                break;
            }
        }

        return(hole);
    }
Example #19
0
    public void UpdateGround(List <Vector3> shapePoints = null)
    {
        // Skip cubes intersected by cutting line
        for (var i = 0; i < shapePoints.Count; i++)
        {
            var cubeX = (int)Mathf.Floor(shapePoints[i].x * _pointsPerUnit);
            var cubeZ = (int)Mathf.Floor(shapePoints[i].z * _pointsPerUnit);
            if (!_skippedQuads[cubeX, 0, cubeZ])
            {
                _skippedQuads[cubeX, 0, cubeZ] = true;
                // Debug.DrawLine(
                //     (new Vector3(cubeX, 0, cubeZ) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                //     (new Vector3(cubeX, 1, cubeZ) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                //     Color.green,999);
            }
        }

        // Find floating islands and drop them
        for (int z = 1; z < _zPoints - 1; z++)
        {
            for (int x = 1; x < _xPoints - 1; x++)
            {
                if (MyMaths.ContainsPoint(shapePoints, (new Vector3(x, 0, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit))
                {
                    _skippedQuads[x, 0, z] = true;
                    // Debug.DrawLine(
                    //     (new Vector3(x, 0, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                    //     (new Vector3(x, 2, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                    //     Color.yellow, 999);
                }
            }
        }

        RegenerateMesh(shapePoints);

        var hole  = CreateHoleObject(shapePoints);
        var walls = CreateHoleWallObject(shapePoints);

        GiveHoleACollider(hole);

        Signals.Get <HoleGeneratedSignal>().Dispatch(hole, walls);
        // Debug.Log($"HoleGeneratedSignal F={Time.frameCount}", gameObject);

        _holeId++;
    }
Example #20
0
    private void UpdateGravity(float deltaT)
    {
        for (int i = 0; i < Particle.Instances.Count; i++)
        {
            if (i != index && Particle.Instances[i].HasGravity == true)
            {
                Vector3 radius = gameObject.transform.position - SimulateController.ParticleInstances[i].transform.position;

                float sizeOfRadiusSquared = Mathf.Pow(MyMaths.Vector_Magnitude(radius), 2);
                if (sizeOfRadiusSquared > 0)
                {
                    Vector3 acceleration       = radius.normalized * GraviationalConstant * Particle.Instances[index].Mass / sizeOfRadiusSquared;
                    Vector3 additionalVelocity = acceleration * deltaT;
                    SimulateController.ParticleInstances[i].GetComponent <ParticleInfo>().Velocity += additionalVelocity;
                    Debug.Log("Additional velocity : " + additionalVelocity);
                }
            }
        }
    }
Example #21
0
    private Vector3 GetAccellerationGravity(newParticle particle)
    {
        Vector3 sum           = Vector3.zero;
        Vector3 positionDelta = Vector3.zero;

        foreach (newParticle planet in newParticle.ParticleInstances)
        {
            if (planet.hasGravity && planet.hasMass)
            {
                positionDelta = planet.MyGameObject.transform.position - particle.MyGameObject.transform.position;
                //Cannot divide by 0
                if (positionDelta != Vector3.zero)
                {
                    sum += planet.mass * positionDelta / Mathf.Pow(MyMaths.Vector_Magnitude(positionDelta), 3);
                }
            }
        }
        return(G * sum);
    }
Example #22
0
    // V^2 = u^2 + 2as
    public static void RanOn_11010(Particle values, int i)
    {
        float insideRoot = Mathf.Pow(values.InitialVelociy[i], 2) + (2 * values.Acceleration[i] * values.Displacement[i]);

        if (insideRoot < 0)
        {
            values.inValidInput[i] = true;
        }
        else
        {
            values.FinalVelocity[i] = MyMaths.SquareRoot(insideRoot);
            //Checking direction which is lost by squaring
            if (values.Acceleration[i] < 0 && values.Displacement[i] <= 0)
            {
                values.FinalVelocity[i] = -values.FinalVelocity[i];
            }
            values.Key[i] = ReplaceAtIndex(2, '1', values.Key[i]);
        }
    }
Example #23
0
        public Vector2 BoxIntersection(BoxCollider bc, Vector2 lineStart, Vector2 boxPosition)
        {
            LineCollider topRight   = new LineCollider(new Vector2(boxPosition.X, boxPosition.Y));
            LineCollider BottomLeft = new LineCollider(new Vector2(boxPosition.X + bc.Size.X, boxPosition.Y + bc.Size.Y));

            Vector2 intersection = Vector2.Zero;

            if (DoesIntersect(topRight, lineStart, boxPosition + new Vector2(0, bc.Size.Y)))
            {
                intersection = Intersection(topRight, lineStart, boxPosition + new Vector2(0, bc.Size.Y));
            }

            if (DoesIntersect(topRight, lineStart, boxPosition + new Vector2(bc.Size.X, 0)))
            {
                Vector2 tempIntersection = Intersection(topRight, lineStart, boxPosition + new Vector2(bc.Size.X, 0));
                if (MyMaths.DistanceCubed(lineStart, tempIntersection) > MyMaths.DistanceCubed(lineStart, intersection))
                {
                    intersection = tempIntersection;
                }
            }

            if (DoesIntersect(BottomLeft, lineStart, boxPosition + new Vector2(bc.Size.X, 0)))
            {
                Vector2 tempIntersection = Intersection(BottomLeft, lineStart, boxPosition + new Vector2(bc.Size.X, 0));
                if (MyMaths.DistanceCubed(lineStart, tempIntersection) > MyMaths.DistanceCubed(lineStart, intersection))
                {
                    intersection = tempIntersection;
                }
            }

            if (DoesIntersect(BottomLeft, lineStart, boxPosition + new Vector2(0, bc.Size.Y)))
            {
                Vector2 tempIntersection = Intersection(BottomLeft, lineStart, boxPosition + new Vector2(0, bc.Size.Y));
                if (MyMaths.DistanceCubed(lineStart, tempIntersection) > MyMaths.DistanceCubed(lineStart, intersection))
                {
                    intersection = tempIntersection;
                }
            }

            return(intersection);
        }
Example #24
0
        public override void Update(GameTime gameTime)
        {
            if (deleteTimer.CheckAndTick())
            {
                DestroyObject();
            }

            Position = startPosition;
            for (int i = 0; i < 20; i++)
            {
                Position += speed;
                if (hb.PlaceMeeting <WallObject>(Position))
                {
                    break;
                }
            }

            thickness = MyMaths.Lerp(thickness, 0, .15f);

            base.Update(gameTime);
        }
Example #25
0
    //Ran when user hovers and clicks over a collider
    private void OnMouseDrag()
    {
        int   index    = gameObject.GetComponent <newCollisionsController>().particleIndex;
        float diameter = newParticle.ParticleInstances[index].diameter;

        Vector3 mousePosition = new Vector3(
            Input.mousePosition.x,
            Input.mousePosition.y,
            distance);
        Vector3 objectPosition = Camera.main.ScreenToWorldPoint(mousePosition);
        //changes object position but restricts the position to be inside of the borders
        float minX = BorderLeft.transform.position.x + diameter / 2 + (BorderLeft.GetComponent <Renderer>().bounds.size.x / 2);
        float maxX = BorderRight.transform.position.x - diameter / 2 - (BorderRight.GetComponent <Renderer>().bounds.size.x / 2);

        float minY = BorderBottom.transform.position.y + diameter / 2 + (BorderBottom.GetComponent <Renderer>().bounds.size.y / 2);
        float maxY = BorderTop.transform.position.y - diameter / 2 - (BorderTop.GetComponent <Renderer>().bounds.size.y / 2);

        objectPosition.x   = MyMaths.Clamp(objectPosition.x, minX, maxX);
        objectPosition.y   = MyMaths.Clamp(objectPosition.y, minY, maxY);
        transform.position = objectPosition;
    }
Example #26
0
        public long Answer(params long[] arguments)
        {
            MyMaths mm         = new MyMaths();
            long    awnser     = 0;
            bool    largeprime = false;

            int i = 0;

            while (!largeprime)
            {
                int prime = mm.PrimaAtPosition(i++);
                if (prime > 2000000)
                {
                    largeprime = true;
                    continue;
                }
                awnser += prime;
            }

            return(awnser);
        }
Example #27
0
        public long Answer(params long[] arguments)
        {
            int[] sequence = { 0, 1, 2, 3, 4 };
            int   maxVal   = 0;
            int   maxVal2  = 0;

            // for permutations of sequence
            // do this

            var perm = MyMaths.GeneratePermutations(sequence, null);

            foreach (var perms in perm)
            {
                int ampA = amplifier.RunCode(program.ToList(), new int[] { perms[0], 0 });
                int ampB = amplifier.RunCode(program.ToList(), new int[] { perms[1], ampA });
                int ampC = amplifier.RunCode(program.ToList(), new int[] { perms[2], ampB });
                int ampD = amplifier.RunCode(program.ToList(), new int[] { perms[3], ampC });
                int ampE = amplifier.RunCode(program.ToList(), new int[] { perms[4], ampD });

                if (ampE > maxVal)
                {
                    maxVal = ampE;
                }

                /*
                 * amplifier2 = new IntCodeProcessor2(program) { InputModeSetting = IntCodeProcessor2.InputMode.Set, InputNumbers = new List<long> { perms[0], 0 } };
                 *
                 * int ampA2 = amplifier2.Run();
                 * int ampB2 = amplifier2.Run(program.ToList(), new int[] { perms[1], ampA });
                 * int ampC2 = amplifier2.Run(program.ToList(), new int[] { perms[2], ampB });
                 * int ampD2 = amplifier2.Run(program.ToList(), new int[] { perms[3], ampC });
                 * int ampE2 = amplifier2.Run(program.ToList(), new int[] { perms[4], ampD });
                 *
                 * if (ampE2 > maxVal2)
                 *  maxVal2 = ampE2;
                 */
            }

            return(maxVal);
        }
Example #28
0
    private void CreateMoon(newParticle earth)
    {
        newParticle moon = newParticle.CreateGravityParticle();

        moon.diameter = 0.1f;
        moon.mass     = 0.012f;
        moon.MyGameObject.transform.position = new Vector3(
            0,
            4f,
            0);
        moon.MyGameObject.name = "Moon";
        //Changes sprite to a moon-like sprite
        moon.MyGameObject.GetComponent <SpriteRenderer>().sprite = Resources.Load("Planet_Sprites\\Ice-Planet", typeof(Sprite)) as Sprite;
        Vector3 deltaPosition = moon.MyGameObject.transform.position - earth.MyGameObject.transform.position;

        //Velocity in X component required for perfect circular motion
        moon.initialVelocity = new Vector3(
            Mathf.Sqrt(newSimulateController.G * earth.mass / MyMaths.Vector_Magnitude(deltaPosition)),
            0,
            0);
        newParticle.ParticleInstances.Add(moon);
    }
Example #29
0
    private void AddPointAndCheckIfCrossed(Vector3 newPoint)
    {
        _trailPoints.Add(newPoint);
        _trailTimes.Add(DateTime.Now);

        if (_trailPoints.Count < 4)
        {
            return;
        }
        var penultimatePoint = _trailPoints[_trailPoints.Count - 2];

        GameDataManager.I.TotalTrailLength += (newPoint - penultimatePoint).magnitude / 100f;

        for (var i = 0; i < _trailPoints.Count - 2; i++)
        {
            if (MyMaths.AreLinesIntersecting(_trailPoints[i], _trailPoints[i + 1], penultimatePoint, newPoint))
            {
                var shapePoints = _trailPoints.Skip(i).ToList();

                if (MyMaths.IsClockwise(shapePoints))
                {
                    shapePoints.Reverse();
                    // Can't have Clockwise shape, the walls then are generated inside out
                }

                _dynamicGround.UpdateGround(shapePoints);
                DrawArea(i);

                // Cut off all tail
                CutTailAtIndex(_trailPoints.Count - 1);
                _trailRendererCutting.Clear();
                SoundManager.I.Play("vaporize", 1f, true);
                return;
            }
        }

        // Debug.Log($"trail.Count={trailPoints.Count}");
    }
Example #30
0
    private void OnHoleGenerated(Transform hole, Transform holeWall)
    {
        holeWall.localScale = new Vector3(1, 50, 1);

        // Less shaking for holes farther from camera
        var distance                  = Vector3.Distance(Camera.main.transform.position, holeWall.position);
        var percentageDistance        = Mathf.Clamp01((distance - minD) / (maxD - minD));
        var distanceFromCameraPenalty = (1 - percentageDistance) * 1.2f;

        var shapeLength = MyMaths.ShapeLength(hole.GetComponent <MeshFilter>().mesh.vertices);

        var lenghtBonus = 1 + (Mathf.Clamp01((shapeLength - minL) / (maxL - minL)) * .5f);

        // Debug.Log($"shapeLength={shapeLength} lenghtBonus={lenghtBonus} distance={distance} distanceFromCameraPenalty={distanceFromCameraPenalty}");

        Sequence sequence = DOTween.Sequence();

        sequence.AppendCallback(() =>
        {
            holeWall.gameObject.SetActive(true);
            Signals.Get <ShakeCameraSignal>().Dispatch(beamDuration, shakeMagnitude * distanceFromCameraPenalty * lenghtBonus);
            hole.gameObject.SetActive(true);
        });
        sequence.AppendInterval(beamDuration);
        sequence.AppendCallback(() =>
        {
            holeWall.gameObject.SetActive(false);
        });
        sequence.AppendCallback(() =>
        {
            var mat = hole.GetComponent <Renderer>().material;
            DOVirtual.Float(.05f, 1, 2.5f, (percentage) =>
            {
                var eased = DOVirtual.EasedValue(0, 1, percentage, Ease.OutQuad);
                mat.SetFloat(SliceAmount, eased);
            });
        });
    }