Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

"Mouse Tail" Geometry

Started by AntP Aug 26, 2011 at 2:42 PM 0 replies 1.2k views
Original Post
AntP
AntP
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:


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.
Kobo
Kobo
You could add a variable that tracks how much movement and rotation has occurred since the last time you updated the tail. Once it reaches a certain threshold (that would be reachable every frame during normal movement and less often when it's really slow), set a flag to true and reset the movement tracker. Only update the tail when the flag is set and then put the flag back to false at the end of the tail update.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.