Windows 7 Forums
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

Microsoft Windows 7 Ultimate 64-bit SP1
 
 
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 SpecsSystem Spec
.

Reply

 2D Smooth Character Control





Thread Tools



Similar help and support threads for2: 2D Smooth Character Control
Thread Forum
How much RAM will I need to run Skyrim smooth? Gaming
Smooth scrolling Customization
WMP Video too smooth Music, Pictures & Video
Smooth Edges Themes and Styles
Smooth scrolling? General Discussion
cs1.6 mouse smooth Gaming
Slow deletes (character by character) General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:31 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33