Spot the bug…

6 09 2010

Two posts, in one day, with a sick daughter… The man knows no rest!

Well, actually this isn’t a full post; just a minor correction. Two points* to those that spotted the minor logic bug hidding in the previous post’s code. I didn’t at first, then I ran the code, the character ran right; I pushed left and let go and watched him slide all the way out of the screen. I laughed then realized what I did wrong; do you?

See, my logic said before to apply friction in the opposite direction of the character’s FACING, this meant that when I turned the character around but didn’t continue moving the friction was actually applied to the direction of my current velocity… Hilarity ensued.

Easily fixed. Apply friction in the opposite direction of the current velocity. In pseudo-code [since I don’t have time for full code].
if (VelocityNow > 0) { VelocityNow = VelocityNow - Friction; }
if (VelocityNow < 0) { VelocityNow = VelocityNow + Friction; }

Hopefully nothing else goes wrong today.

*Since there aren’t any prizes, here take three

“Just another brick in the wall”

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: