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

Set the linear velocity of the center of mass.
public SetLinearVelocity ( System.Vector2 v ) : void
v System.Vector2 The new linear velocity of the center of mass.
Результат void
Пример #1
0
		public override void Keyboard(System.Windows.Forms.Keys key)
		{
			switch (key)
			{
				case System.Windows.Forms.Keys.B:
					if (_bullet != null)
					{
						_world.DestroyBody(_bullet);
						_bullet = null;
					}
					{
						CircleDef sd = new CircleDef();
						sd.Density = 20.0f;
						sd.Radius = 0.25f;
						sd.Restitution = 0.05f;

						BodyDef bd = new BodyDef();
						bd.IsBullet = true;
						bd.Position.Set(-31.0f, 5.0f);

						_bullet = _world.CreateBody(bd);
						_bullet.CreateFixture(sd);
						_bullet.SetMassFromShapes();

						_bullet.SetLinearVelocity(new Vec2(400.0f, 0.0f));
					}
					break;
			}
		}
Пример #2
0
        float limitVelocity(Body hull, float max)
        {
            Vec2 velocity = hull.GetLinearVelocityFromLocalPoint(Box2DX.Common.Vec2.Zero);

            var vec1 = hull.GetXForm().R.Col2;
            var projection = Vec2.Dot(velocity, vec1);
            vec1 *= projection;

            var A = vec1.Length();
            if (A > max)
            {
                var k = max / A;
                hull.SetLinearVelocity(vec1 * k);
            }
            return A;
        }
Пример #3
0
        public void LaunchBomb(Vec2 position, Vec2 velocity)
        {
            if (_bomb != null)
            {
                _world.DestroyBody(_bomb);
                _bomb = null;
            }

            BodyDef bd = new BodyDef();
            bd.AllowSleep = true;
            bd.Position = position;

            bd.IsBullet = true;
            _bomb = _world.CreateBody(bd);
            _bomb.SetLinearVelocity(velocity);

            CircleShape circle = new CircleShape();
            circle._radius = 0.3f;

            FixtureDef fd = new FixtureDef();
            fd.Shape = circle;
            fd.Density = 20.0f;
            fd.Restitution = 0.1f;

            Vec2 minV = position - new Vec2(0.3f, 0.3f);
            Vec2 maxV = position + new Vec2(0.3f, 0.3f);

            AABB aabb = new AABB();
            aabb.LowerBound = minV;
            aabb.UpperBound = maxV;

            _bomb.CreateFixture(fd);
        }
Пример #4
0
		public void LaunchBomb()
		{
			if (_bomb != null)
			{
				_world.DestroyBody(_bomb);
				_bomb = null;
			}

			BodyDef bd = new BodyDef();
			bd.AllowSleep = true;
			bd.Position.Set(Box2DX.Common.Math.Random(-15.0f, 15.0f), 30.0f);
			bd.IsBullet = true;
			_bomb = _world.CreateBody(bd);
			_bomb.SetLinearVelocity(-5.0f * bd.Position);

			CircleDef sd = new CircleDef();
			sd.Radius = 0.3f;
			sd.Density = 20.0f;
			sd.Restitution = 0.1f;
			_bomb.CreateShape(sd);

			_bomb.SetMassFromShapes();
		}