Join Forum | Login | Today's Posts | Tutorials | Windows 10 Forum | Windows 8 Forum

 Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

# Windows 7: 2D Smooth Character Control

 24 Jun 2013 #1 Semicolon Microsoft Windows 7 Ultimate 64-bit SP1 41 posts Buffalo, New York 2D Smooth Character Control I know this isn't primarily a programming forum, but everyone is so helpful I figured someone might be able to help. I am currently working on a 2D game in Java and have a character moving on a 2D plane. Right now the control is pretty choppy and I would like to smooth it out. Here is the relevant code I have: Code: ``` public void moveUp() { if(dy-1 > -maxSpeed){ dy--; } } public void moveLeft() { if(dx-1 > -maxSpeed){ dx--; } } public void moveDown() { if(dy+1 < maxSpeed){ dy++; } } public void moveRight() { if(dx+1 < maxSpeed){ dx++; } } public void update(applet applet) { distanceToCentre = Math.sqrt((x+dx+(size/2)-1-349)*(x+dx+(size/2)-1-349)+(y+dy+(size/2)-1-349)*(y+dy+(size/2)-1-349)); if(distanceToCentre>340){ dx=0; dy=0; } x += dx; y += dy; System.out.println(x + " " + y + " " + distanceToCentre); }``` I was thinking about using some sort of function that the derivative gets smaller as the input increases (like log(x)/log(10)) but using log in Java takes too long. My System Specs