Duality.Components.Physics.RigidBody.ApplyWorldImpulse C# (CSharp) Метод

ApplyWorldImpulse() публичный Метод

Applies a world impulse to the objects mass center. You don't usually need to apply Time.TimeMult here because it is inteded to be a one-time force impact.
public ApplyWorldImpulse ( System.Vector2 impulse ) : void
impulse System.Vector2
Результат void
        public void ApplyWorldImpulse(Vector2 impulse)
        {
            MathF.CheckValidValue(impulse);
            if (this.body == null) return;
            this.body.ApplyLinearImpulse(
                PhysicsConvert.ToPhysicalUnit(impulse) / Time.SPFMult);
        }

Same methods

RigidBody::ApplyWorldImpulse ( System.Vector2 impulse, System.Vector2 applyAt ) : void

Usage Example

Пример #1
0
        private void FireBullet(RigidBody body, Transform transform, Vector2 localPos, float localAngle)
        {
            ShipBlueprint blueprint = this.blueprint.Res;
            if (blueprint.BulletType == null) return;

            Bullet bullet = blueprint.BulletType.Res.CreateBullet();

            Vector2 recoilImpulse;
            Vector2 worldPos = transform.GetWorldPoint(localPos);
            bullet.Fire(this.owner, body.LinearVelocity, worldPos, transform.Angle + localAngle, out recoilImpulse);
            body.ApplyWorldImpulse(recoilImpulse);

            Scene.Current.AddObject(bullet.GameObj);

            SoundInstance inst = null;
            if (Player.AlivePlayers.Count() > 1)
                inst = DualityApp.Sound.PlaySound3D(this.owner.WeaponSound, new Vector3(worldPos));
            else
                inst = DualityApp.Sound.PlaySound(this.owner.WeaponSound);
            inst.Volume = MathF.Rnd.NextFloat(0.6f, 1.0f);
            inst.Pitch = MathF.Rnd.NextFloat(0.9f, 1.11f);
        }