public void Impact(ImpactEvent evt, TankNode tank)
        {
            Rigidbody rigidbody = tank.rigidbody.Rigidbody;
            Vector3   position  = MathUtil.LocalPositionToWorldPosition(evt.LocalHitPoint, rigidbody.gameObject);

            rigidbody.AddForceAtPositionSafe(evt.Force, position);
        }
Esempio n. 2
0
 public static void ApplyVulcanForce(Vector3 force, Rigidbody body, Vector3 pos, TankFallingComponent tankFalling, TrackComponent tracks)
 {
     body.AddForceAtPositionSafe(force, pos);
     if (!tankFalling.IsGrounded && ((tracks.LeftTrack.numContacts + tracks.RightTrack.numContacts) <= 0))
     {
         body.AddForceSafe(-force);
     }
 }
Esempio n. 3
0
        public static bool ApplyDepenetrationForce(Rigidbody body1, BoxCollider collider1, Rigidbody body2, BoxCollider collider2)
        {
            if (!CalculateForcePointAndDir(body1, collider1, body2, collider2))
            {
                return(false);
            }
            float   num     = body2.mass / body1.mass;
            Vector3 zero    = Vector3.zero;
            Vector3 vector2 = Vector3.zero;
            Vector3 lhs     = Vector3.Project(-body1.GetPointVelocity(forcePoint), forceDir.normalized);

            if (Vector3.Dot(lhs, forceDir) > 0f)
            {
                zero    = ((lhs * 0.5f) * ABSORTION_KOEF) * num;
                vector2 = ((-lhs * 0.5f) * ABSORTION_KOEF) / num;
            }
            float magnitude = lhs.magnitude;
            float num3      = num * DEP_VELOCITY;

            if (magnitude < num3)
            {
                zero += forceDir * (num3 - magnitude);
            }
            body1.AddForceAtPositionSafe((zero * body1.mass) / Time.fixedDeltaTime, forcePoint);
            body2.AddForceAtPositionSafe((vector2 * body2.mass) / Time.fixedDeltaTime, forcePoint);
            lhs = Vector3.Project(-body1.GetPointVelocity(forcePoint), vertforceDir.normalized);
            if (Vector3.Dot(lhs, vertforceDir) > 0f)
            {
                zero = (lhs * 0.5f) * 0.1f;
                body1.AddForceAtPositionSafe((zero * body1.mass) / Time.fixedDeltaTime, forcePoint);
            }
            else
            {
                magnitude = lhs.magnitude;
                if (magnitude < VERT_DEP_VELOCITY)
                {
                    zero = vertforceDir * (VERT_DEP_VELOCITY - magnitude);
                    body1.AddForceAtPositionSafe((zero * body1.mass) / Time.fixedDeltaTime, forcePoint);
                }
            }
            return(true);
        }
Esempio n. 4
0
 private void ApplyForceFromRay(SuspensionRay ray, Rigidbody rigidbody, Vector3 bodyForwardAxis, float forcePerRay)
 {
     if (ray.hasCollision)
     {
         float num = Mathf.Abs(Mathf.Acos(ray.rayHit.normal.normalized.y));
         if (num < 1.047198f)
         {
             float num2 = forcePerRay;
             if (num > 1.047198f)
             {
                 num2 *= (1.047198f - num) / 0.2617994f;
             }
             Vector3 force = bodyForwardAxis * num2;
             rigidbody.AddForceAtPositionSafe(force, ray.GetGlobalOrigin());
         }
     }
 }