当前位置: 首页>>代码示例>>C#>>正文


C# Body.ApplyLinearImpulse方法代码示例

本文整理汇总了C#中FarseerPhysics.Dynamics.Body.ApplyLinearImpulse方法的典型用法代码示例。如果您正苦于以下问题:C# Body.ApplyLinearImpulse方法的具体用法?C# Body.ApplyLinearImpulse怎么用?C# Body.ApplyLinearImpulse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FarseerPhysics.Dynamics.Body的用法示例。


在下文中一共展示了Body.ApplyLinearImpulse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NetworkCollisionRemnant

        public NetworkCollisionRemnant(Vector2 position, float size, float angleOfStartForce, int ownerId, Color color, World world, Player creator)
            : base(position, size, color, null, creator)
        {
            OwnerId = ownerId;

            body = BodyFactory.CreateBody(world);
            body.BodyType = BodyType.Dynamic;
            body.Position = ConvertUnits.ToSimUnits(position);
            body.FixedRotation = true;
            body.LinearDamping = 0.8f;

            //Create the vertices that will create the collision shape
            Vertices verts = new Vertices();
            verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
            verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
            verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
            verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));

            //Create the shape and attach it to the body
            PolygonShape s = new PolygonShape(verts, 0);
            body.CreateFixture(s);
            body.FixtureList[0].IsSensor = true;
            body.UserData = this;

            body.CollidesWith = Category.Cat2;
            body.CollisionCategories = Category.Cat2;
            //body.OnSeparation += body_OnSeparation;

            body.ApplyLinearImpulse(new Vector2((float)Math.Cos(angleOfStartForce),(float)Math.Sin(angleOfStartForce)) * 10f);
        }
开发者ID:TheKalleAnka,项目名称:ShapeSpace,代码行数:30,代码来源:NetworkCollisionRemnant.cs

示例2: Load

		protected override void Load()
		{
			_body = BodyFactory.CreateCircle(World, _radius, 0.1f, _position);
			_body.IsStatic = false;
			_body.IsBullet = true;
			_body.ApplyLinearImpulse(_velocity);
		}
开发者ID:JacobRichardt,项目名称:PolkaDotted.SkyRunner,代码行数:7,代码来源:Bullet.cs

示例3: Entity2D

 protected Entity2D(Vector2D position, Vector2D size, float mass)
 {
     World.Add(this);
     this.size = size;
     body = BodyFactory.CreateRectangle(World.world2D,
         size.x * ToPhysicsSize, size.y * ToPhysicsSize, 1,
         position * ToPhysicsSize);
     body.BodyType = BodyType.Dynamic;
     body.Mass = mass;
     body.Friction = 0.2f;
     body.Restitution = 0.98f;
     body.ApplyLinearImpulse(new Vector2(0.1f, 0.5f));
 }
开发者ID:BenjaminNitschke,项目名称:PhysicsCourse,代码行数:13,代码来源:Entity2D.cs

示例4: PingMine

 public PingMine(Player owner, float angle, World world, MainGameScreen game, Color color)
 {
     this.owner = owner;
     this.world = world;
     this.game = game;
     this.color = color;
     body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(10f), ConvertUnits.ToSimUnits(3f), 1f, owner.Body.Position);
     body.BodyType = BodyType.Dynamic;
     body.UserData = "invisible";
     body.IsBullet = true;
     body.Rotation = angle + MathHelper.PiOver2;
     Vector2 impulse = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 0.01f;
     body.ApplyLinearImpulse(impulse);
     body.OnCollision += body_OnCollision;
     traveling = true;
     sonarRotation = 0;
     sonarDistance = 150f;
     sonarPoints = new List<TempPingInstance>();
     sonarPings = new List<TempPingInstance>();
     sonarResolution = 1000f;
     reverseRotation = false;
 }
开发者ID:JoshIzza,项目名称:Submarine,代码行数:22,代码来源:PingMine.cs

示例5: applyLimbThrust

        private void applyLimbThrust(Body limb, double angleOffset, float thrustFactor)
        {
            float rot = limb.Rotation + (float)angleOffset;
            Vector2 vec = new Vector2((float)Math.Cos(rot), (float)Math.Sin(rot));
            limb.ApplyLinearImpulse(vec * thrustFactor);

        }
开发者ID:guozanhua,项目名称:KinectRagdoll,代码行数:7,代码来源:JetPack.cs

示例6: Start

		public override void Start()
		{
			base.Start();
			
			CircleShape circ;
			PolygonShape box;
			Fixture fixture;
			RevoluteJoint joint;
			
			// Add 2 ragdolls along the top
			for(int i = 0; i < 2; i++)
			{
				float startX = 70f + Random.value * 20f + 480f * (float)i;
				float startY = (20f + Random.value * 50f) * -1f;
				
				// Head
				Body head = new Body(FSWorldComponent.PhysicsWorld);
				circ = new CircleShape(12.5f / physScale, 1f);
				fixture = new Fixture(head, circ);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.3f;
				head.Position = new FVector2(startX / physScale, startY / physScale);
				head.ApplyLinearImpulse(new FVector2(Random.value * 100f - 50f, Random.value * 100f - 50f), head.Position);
				head.BodyType = BodyType.Dynamic;
				
				// Torso 1
				Body torso1 = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(15f / physScale, 10f / physScale);
				fixture = new Fixture(torso1, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				torso1.Position = new FVector2(startX / physScale, (startY - 28f) / physScale);
				torso1.BodyType = BodyType.Dynamic;
				
				// Torso 2
				Body torso2 = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(15f / physScale, 10f / physScale);
				fixture = new Fixture(torso2, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				torso2.Position = new FVector2(startX / physScale, (startY - 43f) / physScale);
				torso2.BodyType = BodyType.Dynamic;
				
				// Torso 3
				Body torso3 = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(15f / physScale, 10f / physScale);
				fixture = new Fixture(torso3, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				torso3.Position = new FVector2(startX / physScale, (startY - 58f) / physScale);
				torso3.BodyType = BodyType.Dynamic;
				
				// UpperArm
				// L
				Body upperArmL = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(18f / physScale, 6.5f / physScale);
				fixture = new Fixture(upperArmL, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				upperArmL.Position = new FVector2((startX - 30f) / physScale, (startY - 20f) / physScale);
				upperArmL.BodyType = BodyType.Dynamic;
				// R
				Body upperArmR = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(18f / physScale, 6.5f / physScale);
				fixture = new Fixture(upperArmR, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				upperArmR.Position = new FVector2((startX + 30f) / physScale, (startY - 20f) / physScale);
				upperArmR.BodyType = BodyType.Dynamic;
				
				// LowerArm
				// L
				Body lowerArmL = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(17f / physScale, 6f / physScale);
				fixture = new Fixture(lowerArmL, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				lowerArmL.Position = new FVector2((startX - 57f) / physScale, (startY - 20f) / physScale);
				lowerArmL.BodyType = BodyType.Dynamic;
				// R
				Body lowerArmR = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(17f / physScale, 6f / physScale);
				fixture = new Fixture(lowerArmR, box);
				fixture.Friction = 0.4f;
				fixture.Restitution = 0.1f;
				lowerArmR.Position = new FVector2((startX + 57f) / physScale, (startY - 20f) / physScale);
				lowerArmR.BodyType = BodyType.Dynamic;
				
				// UpperLeg
				// L
				Body upperLegL = new Body(FSWorldComponent.PhysicsWorld);
				box = new PolygonShape(1f);
				box.SetAsBox(7.5f / physScale, 22f / physScale);
//.........这里部分代码省略.........
开发者ID:frotein,项目名称:TinyUniverse,代码行数:101,代码来源:RagdollTest.cs


注:本文中的FarseerPhysics.Dynamics.Body.ApplyLinearImpulse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。