private void ResolveVelocity(float duration)
    {
        float separatingVelocity = CalculateSeparatingVelocity();

        if (-separatingVelocity > 0)
        {
            return;
        }

        float newSeparatingVelocity = -separatingVelocity * restitution;

        Vector3 accelerationCausedVelocity = particle.GetAcceleration();

        float accelerationCausedSeparatingVelocity = accelerationCausedVelocity.ScalarProduct(contactNormal) * duration;

        if (accelerationCausedSeparatingVelocity < 0)
        {
            newSeparatingVelocity += restitution * accelerationCausedSeparatingVelocity;
            if (newSeparatingVelocity < 0)
            {
                newSeparatingVelocity = 0;
            }
        }

        float   deltaVelocity = newSeparatingVelocity - separatingVelocity;
        Vector3 impulse       = contactNormal * deltaVelocity;
        Vector3 totalVelocity = particle.GetVelocity() + impulse;

        particle.SetVelocity(totalVelocity.x, totalVelocity.y, totalVelocity.z);
    }
    void Start()
    {
        startPos = new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z);
        Scene scene = SceneManager.GetActiveScene();

        levelName = scene.name;
        if (levelName == "Level_1")
        {
            controlMode = ControlMode.noControl;
            textPanel.SetActive(true);
            text.text = "Bob's communication with the base is cut off. He needs to go there to check the situation and recharge his suit";
        }
        else if (levelName == "Level_2")
        {
            isSpringLevel = true;
        }
        else if (levelName == "Level_3")
        {
            gravityChangeCount = 3;
            controlMode        = ControlMode.noControl;
            textPanel.SetActive(true);
            text.text = "Bob reached the base. All he can see is mostly ashes, the base is exploded and it's the reason he couldn't communicate with them. Bob recharges his suit and goes after another expedition";
        }
        else if (levelName == "Level_4_Friends" || levelName == "Level_4_Shuttle" || levelName == "Level_5_Friends" || levelName == "Level_5_Shuttle")
        {
            gravityChangeCount = 3;
        }
        gravityChangeCountText.text = gravityChangeCount.ToString();
    }
Exemple #3
0
 private void Start()
 {
     tr                = GetComponent <TrailRenderer>();
     startPos          = new Vector3(transform.position.x, transform.position.y, transform.position.z);
     throwableParticle = new Particle(new Vector3(startPos.x, startPos.y, startPos.z), 0.9f, 1f);
     boundingRectangle = new BoundingRectangle(new Vector3(startPos.x, startPos.y, startPos.z), 1, 1);
     particleContact   = new ParticleContact(throwableParticle, 0f, new Vector3());
 }
Exemple #4
0
 private void OnMouseUp()
 {
     if (gameManager.controlMode == GameManager.ControlMode.springControl)
     {
         tr.emitting = true;
         UnityEngine.Vector3 mp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         mp.z = 0;
         Vector3 mousePos = new Vector3(mp.x, mp.y, mp.z);
         anchoredSpring.ApplySpringForce(throwableParticle, mousePos);
     }
 }
    private void ResolveInterpenetration(float duration)
    {
        if (penetration <= 0)
        {
            return;
        }
        Vector3 move          = contactNormal * -penetration;
        Vector3 finalPosition = particle.GetPosition() + move;

        particle.SetPosition(finalPosition.x, finalPosition.y, finalPosition.z);
    }
Exemple #6
0
 private void FixedUpdate()
 {
     if (gameManager.controlMode == GameManager.ControlMode.springControl)
     {
         Vector3 accVector = new Vector3();
         accVector += new Vector3(0, gameManager.gravity, 0);
         throwableParticle.AddForce(accVector.x, accVector.y, accVector.z);
         throwableParticle.Integrate(Time.fixedDeltaTime);
         boundingRectangle.center = throwableParticle.GetPosition();
         transform.position       = throwableParticle.GetPosition().CycloneToUnity();
     }
 }
    public void ApplySpringForce(Particle particle, Vector3 mouseUpVector)
    {
        Vector3 force = new Vector3();

        force = particle.GetPosition() - mouseUpVector;
        float magnitude = force.Magnitude();

        magnitude  = Mathf.Abs(magnitude - restLength);
        magnitude *= springConstant;
        force.Normalize();
        force *= magnitude;
        force *= forceCoeff;
        particle.AddForce(force.x, force.y, force.z);
    }
Exemple #8
0
    void Start()
    {
        Vector3 startPos = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        eventPoint        = new Vector3(100f, -5.1f, 0);
        particle          = new Particle(new Vector3(startPos.x, startPos.y, startPos.z), 0.8f, 1f);
        boundingRectangle = new BoundingRectangle(new Vector3(startPos.x, startPos.y, startPos.z), 1.8f, 2.8f);
        particleContact   = new ParticleContact(particle, 0f, new Vector3());

        Scene scene = SceneManager.GetActiveScene();

        string[] LevelsWithSuit = System.Enum.GetNames(typeof(GameManager.LevelsWithSuit));
        foreach (string level in LevelsWithSuit)
        {
            if (scene.name == level)
            {
                usableSuit = true;
            }
        }
    }
    void Start()
    {
        rectangles = new List <BoundingRectangle>();
        foreach (GameObject gobj in platforms)
        {
            Vector3 center = new Vector3
            {
                x = gobj.transform.position.x,
                y = gobj.transform.position.y,
                z = gobj.transform.position.z
            };
            BoundingRectangle newbr = new BoundingRectangle(center, gobj.transform.lossyScale.x, gobj.transform.lossyScale.y);
            rectangles.Add(newbr);
        }
        Vector3 endPointCenter = new Vector3
        {
            x = endPoint.transform.position.x,
            y = endPoint.transform.position.y,
            z = endPoint.transform.position.z
        };

        endPointRectangle = new BoundingRectangle(endPointCenter, endPoint.transform.lossyScale.x, endPoint.transform.lossyScale.y);

        Vector3 throwableEndPointCenter = new Vector3
        {
            x = throwableEndPoint.transform.position.x,
            y = throwableEndPoint.transform.position.y,
            z = throwableEndPoint.transform.position.z
        };

        throwableEndPointRectangle = new BoundingRectangle(throwableEndPointCenter, throwableEndPoint.transform.lossyScale.x, throwableEndPoint.transform.lossyScale.y);

        Vector3 springBlockCenter = new Vector3
        {
            x = springBlock.transform.position.x,
            y = springBlock.transform.position.y,
            z = springBlock.transform.position.z
        };

        springBlockRectangle = new BoundingRectangle(springBlockCenter, springBlock.transform.lossyScale.x, springBlock.transform.lossyScale.y);
    }
Exemple #10
0
    private void FixedUpdate()
    {
        if (previousY == particle.GetPosition().y)
        {
            grounded = true;
        }
        else
        {
            grounded = false;
        }

        Vector3 accVector = new Vector3();

        if (jump == true)
        {
            jump = false;
            if (grounded == true)
            {
                grounded = false;
                if (gameManager.downwardsGravity)
                {
                    accVector += new Vector3(0, gameManager.jumpAcc, 0);
                }
                else
                {
                    accVector += new Vector3(0, -gameManager.jumpAcc, 0);
                }
            }
        }
        if (right == true)
        {
            accVector += new Vector3(gameManager.runAcc, 0, 0);
            right      = false;
        }
        if (left == true)
        {
            accVector += new Vector3(-gameManager.runAcc, 0, 0);
            left       = false;
        }
        if (jetpacking == true && gameManager.jetpackFuel > 0 && usableSuit)
        {
            grounded = false;
            if (gameManager.downwardsGravity)
            {
                accVector += new Vector3(0, gameManager.jetpackAcc, 0);
            }
            else
            {
                accVector += new Vector3(0, -gameManager.jetpackAcc, 0);
            }
            gameManager.jetpackFuel -= gameManager.jetpackDrainCoeff * Time.fixedDeltaTime;
            jetpacking = false;
        }
        if (grounded == true && gameManager.jetpackFuel < 100f)
        {
            gameManager.jetpackFuel += gameManager.jetpackFillCoeff * Time.fixedDeltaTime;
        }
        gameManager.jetpackFill.fillAmount = gameManager.jetpackFuel / 100;
        if (gameManager.downwardsGravity)
        {
            accVector += new Vector3(0, gameManager.gravity, 0);
        }
        else
        {
            accVector += new Vector3(0, -gameManager.gravity, 0);
        }

        previousY = particle.GetPosition().y;

        particle.SetForceAccum(accVector.x, accVector.y, accVector.z);
        particle.Integrate(Time.fixedDeltaTime);
        boundingRectangle.center = particle.GetPosition();
        transform.position       = particle.GetPosition().CycloneToUnity();
        float x;
        float y;

        if (particle.GetVelocity().x >= 0)
        {
            x = 2;
        }
        else
        {
            x = -2;
        }

        if (gameManager.downwardsGravity)
        {
            y = 2;
        }
        else
        {
            y = -2;
        }

        transform.localScale = new Vector3(x, y, 0f).CycloneToUnity();
    }
    public bool Overlaps(BoundingRectangle boundingRectangle)
    {
        overlaps = false;

        float rightX = center.x + length / 2;
        float leftX  = center.x - length / 2;
        float upperY = center.y + width / 2;
        float lowerY = center.y - width / 2;

        float otherRectangleRightX = boundingRectangle.center.x + boundingRectangle.length / 2;
        float otherRectangleLeftX  = boundingRectangle.center.x - boundingRectangle.length / 2;
        float otherRectangleUpperY = boundingRectangle.center.y + boundingRectangle.width / 2;
        float otherRectangleLowerY = boundingRectangle.center.y - boundingRectangle.width / 2;

        if (otherRectangleLeftX <= leftX && otherRectangleRightX >= leftX)
        {
            if (otherRectangleLowerY <= lowerY && otherRectangleUpperY >= lowerY)
            {
                interpenetratingX = Mathf.Abs(leftX - otherRectangleRightX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = Mathf.Abs(lowerY - otherRectangleUpperY);
                if (width < interpenetratingY)
                {
                    interpenetratingY = width;
                }
                overlaps = true;
            }
            else if (otherRectangleLowerY <= upperY && otherRectangleUpperY >= upperY)
            {
                interpenetratingX = Mathf.Abs(leftX - otherRectangleRightX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = Mathf.Abs(upperY - otherRectangleLowerY);
                if (width < interpenetratingY)
                {
                    interpenetratingY = width;
                }
                overlaps = true;
            }
            else if (otherRectangleLowerY >= lowerY && otherRectangleUpperY <= upperY)
            {
                interpenetratingX = Mathf.Abs(leftX - otherRectangleRightX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = width;
                overlaps          = true;
            }
        }
        else if (otherRectangleLeftX <= rightX && otherRectangleRightX >= rightX)
        {
            if (otherRectangleLowerY <= lowerY && otherRectangleUpperY >= lowerY)
            {
                interpenetratingX = Mathf.Abs(rightX - otherRectangleLeftX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = Mathf.Abs(lowerY - otherRectangleUpperY);
                if (width < interpenetratingY)
                {
                    interpenetratingY = width;
                }
                overlaps = true;
            }
            else if (otherRectangleLowerY <= upperY && otherRectangleUpperY >= upperY)
            {
                interpenetratingX = Mathf.Abs(rightX - otherRectangleLeftX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = Mathf.Abs(upperY - otherRectangleLowerY);
                if (width < interpenetratingY)
                {
                    interpenetratingY = width;
                }
                overlaps = true;
            }
            else if (otherRectangleLowerY >= lowerY && otherRectangleUpperY <= upperY)
            {
                interpenetratingX = Mathf.Abs(rightX - otherRectangleLeftX);
                if (length < interpenetratingX)
                {
                    interpenetratingX = length;
                }
                interpenetratingY = width;
                overlaps          = true;
            }
        }
        if (overlaps)
        {
            if (interpenetratingX >= interpenetratingY)
            {
                penetration = interpenetratingY;
                if (center.y > boundingRectangle.center.y)
                {
                    contactNormal = new Vector3(0f, -1f, 0f);
                }
                else if (center.y < boundingRectangle.center.y)
                {
                    contactNormal = new Vector3(0f, 1f, 0f);
                }
            }
            else
            {
                penetration = interpenetratingX;
                if (center.x > boundingRectangle.center.x)
                {
                    contactNormal = new Vector3(-1f, 0f, 0f);
                }
                else if (center.x < boundingRectangle.center.x)
                {
                    contactNormal = new Vector3(1f, 0f, 0f);
                }
            }
        }
        return(overlaps);
    }
 public BoundingRectangle(Vector3 center, float length, float width)
 {
     this.center = center;
     this.length = length;
     this.width  = width;
 }
    private float CalculateSeparatingVelocity()
    {
        Vector3 velocity = particle.GetVelocity();

        return(velocity.ScalarProduct(contactNormal));
    }
 public ParticleContact(Particle particle, float restitution, Vector3 contactNormal)
 {
     this.particle      = particle;
     this.restitution   = restitution;
     this.contactNormal = contactNormal;
 }
    void LateUpdate()
    {
        Vector3 newCamPos = new Vector3(player.transform.position.x, transform.position.y, transform.position.z);

        transform.position = newCamPos.CycloneToUnity();
    }