Beispiel #1
0
        public virtual void throwObject(Item obj)
        {
            // Throw the given object in the direction the shape is looking.
            // The force value is hardcoded according to the current default
            // object mass and mission gravity (20m/s^2).

            float throwforce = ((SimDataBlock)getDataBlock())["throwForce"].AsFloat();

            if (throwforce == 0)
            {
                throwforce = 20;
            }

            // Start with the shape's eye vector...

            Point3F eye = getEyeVector();
            Point3F vec = eye.vectorScale(throwforce);

            // Add a vertical component to give the object a better arc
            double verticalForce = throwforce / 2.0;
            float  dot           = Point3F.vectorDot(new Point3F("0 0 1"), eye);

            if (dot < 0)
            {
                dot = dot * -1;
            }

            vec = vec + Point3F.vectorScale(new Point3F(string.Format("0 0 {0}", verticalForce)), 1 - dot);
            vec = vec + getVelocity();


            // Set the object's position and initial velocity


            TransformF pos = new TransformF(Util.getBoxCenter(getWorldBox()));


            obj.setTransform(pos);


            obj.applyImpulse(pos.GetPosition(), vec);

            // Since the object is thrown from the center of the shape,
            // the object needs to avoid colliding with it's thrower.

            obj.setCollisionTimeout(this);

            //todo Should we add this code in to destroy things after they have been thrown?
            if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine"))
            {
                obj.schedule("2000", "delete");
            }
        }
Beispiel #2
0
        public string tossPatch()
        {
            if (!isObject())
            {
                return(string.Empty);
            }

            Item item = ItemData.createItem("HealthKitPatch");

            item["istemp"] = true.AsString();

            item["sourceObject"] = this;
            item["static"]       = false.AsString();

            ((SimSet)"MissionCleanup").pushToBack(item);

            Random r = new Random();

            Point3F vec = new Point3F(-1 + (float)r.NextDouble() * 2, -1 * (float)r.NextDouble() * 2, (float)r.NextDouble());

            vec = vec.vecotrScale(10);
            Point3F eye = getEyeVector();
            float   dot = new Point3F("0 0 1 ").vectorDot(eye);

            if (dot < 0)
            {
                dot = -dot;
            }

            vec = vec + new Point3F("0 0 8").vecotrScale(1 - dot);
            vec = vec + getVelocity();

            TransformF pos = new TransformF(getWorldBox().Get_MinExtents());

            item.setTransform(pos);
            item.applyImpulse(pos.GetPosition(), vec);
            item.setCollisionTimeout(this);

            item.SchedulePop();

            return(item);
        }