Пример #1
0
        public List <PhysicsHit> ShootImpaler(float velocity, float hitObjectVelocityMultiplier, float zMovementLimit, Ray ray, float maxDistance, LayerMask mask, float impalerRadius, bool kinematicOnReach, bool useColliderOnReach, float lifeTime, System.Action <PhysicsHit> onReachHitObject)
        {
            this.onReachHitObject   = onReachHitObject;
            this.kinematicOnReach   = kinematicOnReach;
            this.useColliderOnReach = useColliderOnReach;
            this.impalerRadius      = impalerRadius;

            InitializeLaunch(ray, velocity, lifeTime, hitObjectVelocityMultiplier);

            reachedIndicies.Clear();

            //grab any rigidbodies along a ray, until a static collider
            bool hitStatic;

            RagdollPhysics.ShootMultiGrabRay(ray, impalerRadius, mask, maxDistance, grabbedBodies, physicsHits, out endPointDistance, out hitStatic);

            //for each grabbed rigidbody we've impaled,
            // attach it to our impaler rigidbody via a joint
            for (int i = 0; i < grabbedBodies.Count; i++)
            {
                // need to disable kinematic here to avoid jittery physics
                // grabbedGroups[i].grabPoint.baseRigidbody.isKinematic = false;
                RagdollPhysics.GrabRigidbody(grabbedBodies[i].grabPoint.baseRigidbody, rb, false);

                // allow joint movement along teh z axis,
                // so rigidbodies can slide along the impaler (helps stability)
                ConfigurableJoint joint = grabbedBodies[i].grabPoint.baseJoint;
                joint.zMotion = ConfigurableJointMotion.Limited;
                var l = joint.linearLimit;
                l.limit           = zMovementLimit;
                joint.linearLimit = l;
            }

            StartCollisionIgnoreWithMyCollider(physicsHits);

            AdjustCapsulCollider(endPointDistance, impalerRadius);

            return(physicsHits);
        }
Пример #2
0
        public List <PhysicsHit> ShootSpear(float velocity, Ray ray, float maxDistance, LayerMask skewerMask, float lifeTime, float skewerSeperation, float minSpaceFromWall, float hitObjectVelocityMultiplier, System.Action <PhysicsHit, bool> onReachHitObject)
        {
            this.onReachHitObject = onReachHitObject;

            collidedDuringPhysicsFly = false;

            InitializeLaunch(ray, velocity, lifeTime, hitObjectVelocityMultiplier);

            reachedIndicies.Clear();

            //grab any rigidbodies along a ray, until a static collider
            Vector3 endPoint = RagdollPhysics.ShootMultiGrabRay(ray, spearRadius, skewerMask, maxDistance, grabbedBodies, physicsHits, out endPointDistance, out stickToEnd);

            int hitCount = grabbedBodies.Count;

            // if we have no wall to stick to
            if (!stickToEnd)
            {
                //if we have some rigidbodies to impale, recalculate an end point after the last one
                if (hitCount > 0)
                {
                    PhysicsHit furthestHit = physicsHits[hitCount - 1];
                    endPoint         = furthestHit.hitElements[furthestHit.hitElements.Count - 1].hitPoint + ray.direction * spearLength;
                    endPointDistance = Vector3.Distance(ray.origin, endPoint);
                }
                else
                {
                    // turn on physics and just use our velocity to "fly"
                    ReachDestination(1);
                }
            }

            // this is true already if we didnt hit anything
            if (!reachedDestination)
            {
                // if we have any impaled rigidbodies
                if (hitCount > 0)
                {
                    // where each grabbed rigidbody will end up
                    skewerTargets = new Vector3[hitCount];
                    skewerOffsets = new float[hitCount];

                    // the first index that is being skewered
                    startIndexForSkewered = hitCount;

                    // calculate where each grabbed rigidbody will end up:
                    float lastEndPoint = minSpaceFromWall;
                    for (int i = hitCount - 1; i >= 0; i--)
                    {
                        float skewerOffset;
                        skewerTargets[i] = CalculateSkewerTargetPosition(endPoint, ray.direction, skewerSeperation, DetermineHitPointsSize(physicsHits[i], ray.direction, skewerMask), ref lastEndPoint, out skewerOffset);
                        skewerOffsets[i] = skewerOffset;

                        // if we have enough space on teh spear, skewer this index
                        if (skewerOffset < spearLength)
                        {
                            startIndexForSkewered = i;
                        }

                        // if not we'll just add force to it (or dismember it) when the spear reaches it
                    }

                    StartCollisionIgnoreWithMyCollider(physicsHits);

                    DynamicRagdoll.Demo.GameTime.SetTimeDilation(.5f, .1f, 10, .1f);
                }

                // randomly offset the amount the spear model sticks out of the end point
                randomOffset   = Random.Range(-tipLength * .5f, 0);
                modelEndTarget = endPoint + ray.direction * randomOffset;
            }

            return(physicsHits);
        }