Hi All,
I'm trying to simulate snake body movement, the problem is the previous nodes of the snake doesn't follow exactly the head node.
This is my code to update the nodes
for ( int i = 1 ; i < nodes.size(); i++ )
{
Vec2f diff = nodes[i-1].m_Pos -nodes[i].m_Pos;
float length = diff.length();
Vec2f norm = diff.normalized();
nodes[i].m_Pos+=(length - 8)*norm;
}if ( nodes[0].m_Pos.x < 5 )
{
nodes[0].m_Vel.y = -2;
nodes[0].m_Vel.x = 0;
if(nodes[0].counter--<1)
{
nodes[0].m_Vel.y = 0;
nodes[0].m_Vel.x = -2;
nodes[0].counter = 5;
}
}
nodes[0].m_Pos-=nodes[0].m_Vel;
Kindly find attached exe file which shows the problem.