# How to count Score based on position of player?

So, I am making this game where you keep moving forward and there are obstacles in the path. If you collide with an obstacle 100 points are deducted and for every frame a point is deducted i.e. score -= (int) (timeDecrement*Time.deltaTime) You gain points the farther you go down the axis. However, this is presenting a bug I didn't expect. As of now, I am adding the (int) player.position.z to the score. But since the collisions slow you down you actually gain more points than lose. Sometimes you get completely stuck and continuously gain points. Any ideas to how I can solve this?

Edit: Also, the points added per frame gets higher. I was think of solving both of these by finding out how much we moved since last frame. But I can't figure out how to do this. I was thinking of adding a variable that got updated every frame and then we compared the difference and if it were say 10 or 25 we could add the same amount of points. However, with better frames the score is going down to negative instead because the position change is too little. But if the frame rate is low then adding 0.25 points for a 0.25 difference in the coordinates (which I also considered) the points again go down to negative.

You could create a variable pointsLost where you add up all the points you lose. Then your score would be score = player.position.z - pointsLost.