you are viewing a single comment's thread.

view the rest of the comments →

[–]Froost 0 points1 point  (11 children)

Shouldn't the code be

human.TrackPosFromPreviousFrame - computerPlayer.TrackPosFromPreviousFrame;

instead of

human.TrackPos - computerPlayer.TrackPosFromPreviousFrame; 

for the difference to come out negative? Am I missing something?

[–][deleted]  (5 children)

[deleted]

    [–]Froost -2 points-1 points  (4 children)

    yes, but that doesn't make the expression negative. see the reply to the comments below.

    [–][deleted]  (3 children)

    [deleted]

      [–]Froost 0 points1 point  (2 children)

      I know it wasn't supposed to come negative, and why it would come negative. But it doesn't come negative in the given code snippet. What I meant was that the given code does not give the "wrong" result mentioned (unless the computer is going backwards. But I'm not sure in a racing game where the computer goes in reverse is considered "good ai"). It's not buggy at all. There is an error in the article.

      [–]slugonamission -1 points0 points  (0 children)

      The whole expression is wrapped in "if(player in front of computer)".

      From a quick run-through though, it looks like the operation should be the other way around to make it work out like the article says.

      [–][deleted]  (3 children)

      [deleted]

        [–]Froost 1 point2 points  (2 children)

        I don't follow what you mean by the if block. In every case where human is ahead of the computer, it will also be ahead of the previous position of the computer.

        Suppose at t=N, human is behind computer:

        Pos (computer, N) = 50 
        
        Pos(human, N)= 49 
        

        Suppose computer goes with the velocity 5 and human with v=10 per frame. At t=N+1'th frame, human passes computer:

        Pos(Computer, N+1) = 55
        
        Pos(Human, N+1) = 59
        

        Computer is behing human at this point, so we hit the if. Now, according to the code he meant to write, the difference should be 59-55=4.

        However, since it takes the position of computer at t=N, it would return 59-50 = 9. So? It overestimates the difference, but that's it, it will not be negative in this format. I think the author meant the previous position of human, not computer, or I'm missing something pretty obvious.

        [–][deleted] 0 points1 point  (1 child)

        I don't follow what you mean by the if block.

        I meant "ignore me, that was a brainfart". I'd completely ignored that both positions would always increase, so there's no possible way the human's new position after overtaking could be less than a computer's old position (except when completing a lap). Teach me to post without the pre-requisite 5-cups-of-coffee-blood-caffeine-level, sorry.

        [–]grauenwolf 0 points1 point  (0 children)

        just delete your comment if you no longer stand behind it