# Setting a displacement or offset between Snake segements

I have a problem in maths or I do not know. I have drawn few circles that simulates the body of a snake, the head of the snake moves and others should follow. but the is no offset or displacement between the circles, because the current code sets the previous position of the nodes to the current, when I add few numbers to both x, y axis, the body segments get distorted. How do I set the offsets between the segments?

for ( int i = 0 ; i < nodes.size(); i++ )
{
if( i == 0 )
{
// Do calculations for new position

//Set position and previous position
nodes[i].m_PrevPos.x = nodes[i].m_Pos.x;
nodes[i].m_PrevPos.y = nodes[i].m_Pos.y;

}
else
{
nodes[i].m_PrevPos.x = nodes[i-1].m_Pos.x;
nodes[i].m_PrevPos.y = nodes[i-1].m_Pos.y;
nodes[i].m_Pos.x = nodes[i-1].m_PrevPos.x;
nodes[i].m_Pos.y = nodes[i-1].m_PrevPos.y;
}
}


I would like also to check the head's node velocity for example:

 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;
}

}


In fact you don't need to calculate offset for each part in each iterate.

just do it for first part. (How?)

for ( int i = nodes.size()-1 ; i >= 0; --i )
{
if( i != 0 )
{
// Here Do not think about offset. just follow old position of next snake part
nodes[i].m_Pos.x = nodes[i-1]m_Pos.x ;
nodes[i].m_Pos.y = nodes[i-1]m_Pos.y ;
}
else
{
// Do calculations for new position "with a proper offset".
nodes[0].m_Pos.x = .. ;// calculated position
nodes[0].m_Pos.y = .. ;// calculated position
}
}