Original Post
Hi,
I have a simple sprite to represent a mouse and behind the mouse are a chain of overlapping circles to represent the mouse's tail. I currently have the following update method for the mouse and its tail:
Tail is an ArrayList of TailSegment objects, which are basically just simple sprites. This has the effect of curling the tail nicely as the mouse moves and turns, but it has a couple of problems. Particularly when the mouse is moving slowly or is stationary, turning causes the tail to whip around and end perfectly straight as this code results in the tail being lined up behind a mouse after Tail.Count frames. I'd like the tail to move a little more realistically with respect to the movement of the mouse, so turning on the spot or stopping while turning will leave the tail curved, the tail will straighten up more gently if the mouse is moving slowly etc., but as I think about it it starts to sound a little more complex than I initially thought. Can anyone help point me in the right direction when it comes to modelling something like this?
Thanks.
I have a simple sprite to represent a mouse and behind the mouse are a chain of overlapping circles to represent the mouse's tail. I currently have the following update method for the mouse and its tail:
public void Update()
{
Velocity.X = (float)Speed * (float)Math.Cos(Angle);
Velocity.Y = (float)Speed * (float)Math.Sin(Angle);
if ((Position.Y + Velocity.Y < StageHeight - 24) && Position.Y + Velocity.Y > 0)
{
Position.Y += Velocity.Y;
}
if ((Position.X + Velocity.X < StageWidth - 24) && Position.X + Velocity.X > 0)
{
Position.X += Velocity.X;
}
// Update tail positions
{
Tail[0].Position.X = 8 + Position.X - 12 * (float)Math.Cos(Angle);
Tail[0].Position.Y = 8 + Position.Y - 12 * (float)Math.Sin(Angle);
for (int i = 1; i < Tail.Count; i++)
{
Tail.Position.X = Tail[i - 1].Position.X - 4 * (float)Math.Cos(Tail[i - 1].Angle);
Tail.Position.Y = Tail[i - 1].Position.Y - 4 * (float)Math.Sin(Tail[i - 1].Angle);
}
Tail[0].Angle = Angle;
for (int i = Tail.Count - 1; i > 0; i--)
{
Tail.Angle = Tail[i - 1].Angle;
}
}Tail is an ArrayList of TailSegment objects, which are basically just simple sprites. This has the effect of curling the tail nicely as the mouse moves and turns, but it has a couple of problems. Particularly when the mouse is moving slowly or is stationary, turning causes the tail to whip around and end perfectly straight as this code results in the tail being lined up behind a mouse after Tail.Count frames. I'd like the tail to move a little more realistically with respect to the movement of the mouse, so turning on the spot or stopping while turning will leave the tail curved, the tail will straighten up more gently if the mouse is moving slowly etc., but as I think about it it starts to sound a little more complex than I initially thought. Can anyone help point me in the right direction when it comes to modelling something like this?
Thanks.