3
\$\begingroup\$

I saw this question:

How do I implement deceleration for the player character?

Asking how to implement this code In a short and elegant way:

 if speed > 0 then 
    speed = speed - 20 * dt 
    if speed < 0 then 
        speed = 0 
    end 
end 
if speed < 0 then 
    speed = speed + 20 * dt 
    if speed > 0 then 
        speed = 0 
    end 
end 

This was my answer:

sign = (speed >= 0? 1 : -1); 
speed -= sign * 20 * dt // 20 is the rate of deccelaration 
if(sign != (speed >= 0? 1 : -1)) speed = 0; 

It seems to meet the criteria presented by the question and it could be useful in platformers where you wish to deccelerate the chracter on the x- axis and control y-axis with gravity. It is also semantically identical to what the OP requested in the question.

Some people felt the answer was too localized to 1-d games and decided to downvote on that account.

Is that really a bad thing in answer, that it's written to best suit the question without adding more advance tecniques that were not required by the asker?

\$\endgroup\$
6
\$\begingroup\$

People are free to use their negative votes as they see fit; competitive or retributive down-voting, when it occurs, is generally "policed" by the fact that the community as a whole can sway the score of a question or answer much more than one individual can.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .