All pastes #2128134 Raw Edit

420606

public text v1 · immutable
#2128134 ·published 2012-03-14 16:04 UTC
rendered paste body
I decided to try using Lerp to dictate the movement for Attract mode,
but what i can only assume is because of the conversion from Float to Int, after a few times doing the movement it decides it doesnt want to go any further.


her is my code so far
        int[,] attract = new int[,]
        {
            {400,300}, {300,300}, {300,400}, {300,430},
            {100,430}, {100,500}, {100,500}, {10,300},
            {100,300}, {100,100}, {300,100}, {300,50},
            {500,50},  {500,300}, {500,250}, {290,250}, 
            {500,300}, {500,400},  {400,400}, {540, 400},
            {540,500}, {333,500}, {333,700}, {50,700},
            {50,650}
        };

        private void attractMode()
        {

            huToPos = new Vector2(attract[attractPos,0], attract[attractPos,1]);   // take the location of the next rubbish
            PPos = Vector2.Lerp(huPos, huToPos, 0.04f);          // use a lerp to move the human to rubbish
            humanRectangle.X = (int)PPos.X;            //changed actual rectangle
            humanCollisionRect.X = (int)PPos.X;        //changes collision detection rectangle
            humanRectangle.Y = (int)PPos.Y;            //changed actual rectangle
            humanCollisionRect.Y = (int)PPos.Y;        //changes collision detection rectangle
            huPos = new Vector2(humanRectangle.X, humanRectangle.Y);     // update the start potition of the lerp as to move it close and close to the human other wise it would keep reseting the lerp but we want a smooth movement
            if (huPos  == new Vector2(attract[attractPos,0],attract[attractPos,1]))
            {
                attractPos++;
                
            }
            if (attractPos == attract.Length/2) attractPos = 0;
        }


but it gets as close to the third attract array values as 300, 381.95
and moves no further.

i cant figure out why it is never reaching 300,400

if i set the speed to a whole integer 1.00f then its goes through them all as it should, but if i lower into a 0.99 it doesn't and stops at said interval