示例#1
0
    // for the hook
    private void ConstrainTransformAndParticle(Transform givenTransform, ZB_VerletParticle particle)
    {
        //float stretchedLength = segmentLength + stretchLimit;
        Vector3 vectorDelta = givenTransform.position - particle.Position;
        float   deltaLength = vectorDelta.magnitude;

        hookStretchLength = deltaLength - segmentLength;

        if (deltaLength > segmentLength)
        {
            float stretchDeltaRatio = (deltaLength - segmentLength) / deltaLength;

            //particle.Position += vectorDelta * stretchDeltaRatio * 0.5f;
            particle.Position = Vector3.MoveTowards(particle.Position, givenTransform.position, hookStretchLength / 2f);
            if (!ReleaseLine && !avoidHookReactions)
            {
                // elasticity = 35
                // mass = 3
                // drag = 1.34
                // angular drag = 2.5
                // forceMode = velocityChange

                hookDelta = vectorDelta * stretchDeltaRatio * 0.5f;
                //transform.position -= hookDelta;
                givenTransform.position = Vector3.MoveTowards(givenTransform.position, particle.Position, hookStretchLength / 2f);
                //ZB_SceneSingletons.debugText1.text = "Hook stretch: " + Math.Round((Decimal)hookStretchLength, 5, MidpointRounding.AwayFromZero);

                //if (!hooked)
                if (!lineStartRBody.isKinematic)
                {
                    givenTransform.gameObject.GetComponent <Rigidbody>().AddForce(-vectorDelta * stretchDeltaRatio * 0.5f * elasticity, ForceMode.VelocityChange);
                }
            }
            else if (ReleaseLine && totalLength < Vector3.Distance(lineStart.position, lineEnd.position))
            {
                //transform.position -= vectorDelta * diff * 0.5f;
                //print(totalLength);
                //transform.gameObject.GetComponent<Rigidbody>().AddForce(-vectorDelta * diff * 0.2f * elasticity, ForceMode.Force);
                if (!hooked)
                {
                    float hookVelocity = lineStartRBody.velocity.magnitude;
                    if (hookVelocity > reel.initialReleaseSpeed * 2 + 1f)
                    {
                        //print("Adding " + (hookVelocity - reel.initialReleaseSpeed) + " to release speed");
                        reel.releaseSpeed += hookVelocity - reel.initialReleaseSpeed;
                    }
                    else
                    {
                        reel.releaseSpeed = reel.initialReleaseSpeed;
                    }
                }
            }
            else if (avoidHookReactions && !hooked)
            {
                givenTransform.gameObject.GetComponent <Rigidbody>().AddForce(-vectorDelta * stretchDeltaRatio * castMultiplier * elasticity * Time.deltaTime, ForceMode.Force);
            }
        }
    }
    private void ConstrainParticleAndTransform(ZB_VerletParticle particle, Transform transform, float restraintLength, bool releaseLine)
    {
        Vector3 vectorDelta = transform.position - particle.Position;
        float   deltaLength = vectorDelta.magnitude;

        float diff = (deltaLength - restraintLength) / deltaLength;

        particle.Position += vectorDelta * diff * .2f;

        float tipPullForce = (-vectorDelta * diff * 10f).magnitude;
        //transform.gameObject.GetComponent<Rigidbody>().AddForce(-vectorDelta * diff * 0.5f * elasticity);
    }
    private void ConstrainParticles(ZB_VerletParticle particleOne, ZB_VerletParticle particleTwo, float restraintLength)
    {
        Vector3 vectorDelta = particleOne.Position - particleTwo.Position;
        float   deltaLength = vectorDelta.magnitude;

        float diff = (deltaLength - restraintLength) / deltaLength;

        Vector3 change = vectorDelta * diff * 0.5f;

        particleOne.Position -= change;
        particleTwo.Position += change;
    }
    private void ConstrainTransformAndParticle(Transform transform, ZB_VerletParticle particle, float restraintLength)
    {
        Vector3 vectorDelta = transform.position - particle.Position;
        float   deltaLength = vectorDelta.magnitude;


        float diff = (deltaLength - restraintLength) / deltaLength;

        particle.Position += vectorDelta * diff * 0.5f;


        transform.position -= vectorDelta * diff * 0.5f;

        transform.gameObject.GetComponent <Rigidbody>().AddForce(-vectorDelta * diff * 0.5f, ForceMode.VelocityChange);
    }
示例#5
0
    private void Verlet(ZB_VerletParticle particle)
    {
        float deltaTime   = Time.deltaTime;
        float deltaTimeSq = deltaTime * deltaTime;

        Vector3 tempPos       = particle.Position;
        Vector3 positionDelta = particle.Position - particle.OldPosistion;

        if (particle.Position.y > 0f)
        {
            particle.Position += ((positionDelta * (1f - drag * deltaTime) + new Vector3(0f, -gravity * deltaTime, 0f)) + ((particle.Acceleration) * deltaTimeSq));
        }
        else
        {
            //positionDelta.y = 0f;
            particle.Position += ((positionDelta * (1f - 1f * deltaTime) + new Vector3(0f, -underwaterGravity * deltaTime, 0f)) + ((particle.Acceleration) * deltaTimeSq));
        }
        particle.OldPosistion = tempPos;
    }