Пример #1
0
    private void CalculateApplySpeed(ForceObject forceObject, Vector3 normal)
    {
        if (Vector3.Angle(sourceMassObject.GetRecentNetSpeed(), normal) > 90)
        {
            return;
        }

        Vector3 projection = Vector3.Project(sourceMassObject.GetRecentNetSpeed() + sourceMassObject.GetRecentNetAcceleration(), normal); //TODO this bad. better if after physics

        Vector3 speedApplication = projection * massMultiplier / (isPure ? 1 : forceObject.GetMass()) * speedTransferranceMultipler;

        forceObject.DirectAdjustAddSpeed(speedApplication - lastSpeedApplied[forceObject]);

        lastSpeedApplied[forceObject] = speedApplication; //APPLY AFTER SYSTEM? If not work.
    }
    private void GeneralCollisionEnter(ForceObject forceTarget, Vector3 contactFaceNormal)
    {
        Vector3 adjustment = (-Vector3.Project(forceTarget.GetRecentNetSpeed(), contactFaceNormal)) * normalForceInstantBounceMultiplier;

        forceTarget.DirectAdjustAddSpeed(adjustment);

        var normforce = new CustomOppositeAlongNormalForce(contactFaceNormal, normalForceStableMultiplier); //TODO this right now only supports one face. is only good for big platforms etc. anything further may need a deeper mesh-interacting physics though

        normforce.ApplyForce(forceTarget, true, float.NegativeInfinity);
        normalAppliedOn.Add(forceTarget, normforce);
    }
    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        if (!canExertMotorForceCheck())
        {
            //NOT GROUNDED

            //do pure speed efforts

            //Vector3 currentSpeed

            return(Vector3.zero);
        }

        //GROUNDED

        if (pureSpeedDirty)
        {
            UndirtyPureSpeed();
        }

        Vector3 forwardForce  = motorMovementTransform.forward * forwardAccelerations[currentForwardIndex];
        Vector3 rightForce    = motorMovementTransform.right * backwardAccelerations[currentRightIndex];
        Vector3 leftForce     = -motorMovementTransform.right * rightAccelerations[currentLeftIndex];
        Vector3 backwardForce = -motorMovementTransform.forward * leftAccelerations[currentBackwardIndex];

        Vector3 adjustedWalkPlaneSpeed = Vector3.ProjectOnPlane(objectAppliedTo.GetRecentNetSpeed(), groundDir);

        Vector3 resultantForce = forwardForce + rightForce + leftForce + backwardForce;

        if (adjustedWalkPlaneSpeed.magnitude < NoMovementCutoff && resultantForce.magnitude < NoMovementCutoff)
        {
            objectAppliedTo.DirectAdjustAddSpeed(-adjustedWalkPlaneSpeed);
            return(Vector3.zero);
        }

        if (adjustedWalkPlaneSpeed.magnitude > maximumSpeedsPerIndex[currentMaxIndex])
        {
            resultantForce += -adjustedWalkPlaneSpeed.normalized * adjustmentAccelerations[currentMaxIndex];
        }

        //TODO doing it with just if might be faster becasue there is no addition with vector3.zero. Do diagnostic if releasing this code separately.

        return(resultantForce);
    }
Пример #4
0
    //TODO will caching getter values change performance?

    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        return((-objectAppliedTo.GetRecentNetSpeed().normalized *
                Mathf.Lerp(0, objectAppliedTo.GetObjectDragValue(), objectAppliedTo.GetRecentNetSpeed().magnitude / objectAppliedTo.GetAdjustedTrueMaximumSpeed())) * dragForceCoefficient);
    }
Пример #5
0
 public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
 {
     return((Vector3.Project(constantForce, objectAppliedTo.GetRecentNetSpeed()).magnitude > upToSpeed)? Vector3.zero : constantForce);
 }