0
想象一个分段生物,如蜈蚣。通过控制头部段,身体段通过一个点附着到先前的身体段。保留点(2)或Vector2(2)加入点(1)或Vector2(1)
随着头部移动(现在在8个主要/主要方向上),一个点相对于其旋转移动。
public static Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerOfRotation, float angleOfRotation)
{
Matrix rotationMatrix = Matrix.CreateRotationZ(angleOfRotation);
return Vector2.Transform(pointToRotate - centerOfRotation, rotationMatrix);
}
正想在这里发表一个示意图,但你知道...
center(2) point(2) center(1) point(1)
point(1)
point(2) ^ |
/\ |
| |
center(2) center(1) \/
V
我曾经想过用矩形属性/字段为基础的精灵,
private Rectangle bounds = new Rectangle(-16, 16, 32, 32);
和检查主体部分内的预定义点是否位于头部精灵范围内。
虽然我目前在做:
private static void handleInput(GameTime gameTime)
{
Vector2 moveAngle = Vector2.Zero;
moveAngle += handleKeyboardMovement(Keyboard.GetState()); // basic movement, combined to produce 8 angles
// of movement
if (moveAngle != Vector2.Zero)
{
moveAngle.Normalize();
baseAngle = moveAngle;
}
BaseSprite.RotateTo(baseAngle);
BaseSprite.LeftAnchor = RotatePoint(BaseSprite.LeftAnchor,
BaseSprite.RelativeCenter, BaseSprite.Rotation); // call RotatePoint method
BaseSprite.LeftRect = new Rectangle((int)BaseSprite.LeftAnchor.X - 1,
(int)BaseSprite.LeftAnchor.Y - 1, 2, 2);
// All segments use a field/property that is a point which is suppose to rotate around the center
// point of the sprite (left point is (-16,0) right is (16,0) initially
// I then create a rectangle derived from that point to make use of the .Intersets method of the
// Rectangle class
BodySegmentOne.RightRect = BaseSprite.LeftRect; // make sure segments are connected?
BaseSprite.Velocity = moveAngle * wormSpeed;
//BodySegmentOne.RightAnchor = BaseSprite.LeftAnchor;
if (BodySegmentOne.RightRect.Intersects(BaseSprite.LeftRect)) // as long as there two rects occupy the
{ // same space move segment with head
BodySegmentOne.Velocity = BaseSprite.Velocity;
}
}
目前的情况是,段移动头部,但以并行的方式。我想在头部被拖动时获得细分的更细微的移动。
据我所知,这种运动的编码将比我在这里所涉及的要多得多。有关我应该如何看待这个问题的一些提示或指示将不胜感激。
你想自己实现这个,还是使用像Farseer(http://farseerphysics.codeplex.com)这样的物理引擎可以吗?我问的原因是你想做的事情不是微不足道的,而是涉及物理引擎概念的知识。 – Ani
标称的解决方案是写我自己的解决方案;但是,如果使用已建立的系统将加速我提出解决方案的能力,我将全力以赴,并将进一步深入Farseer。 – Dialock