Game Development Community

Gamepad analog sticks super choppy[Resolved, echos are bad]

by Cosmic Logic · in Torque Game Builder · 04/18/2009 (12:28 am) · 2 replies

Hey,

I'm looking for an implementation for using joystick movement.

This is what I'm using (pretty barbaric, I know):

This is the binding:
moveMap.bindObj(getWord(%this.xKey, 0), getWord(%this.xKey, 1), "joyMoveX", %this);
		moveMap.bindObj(getWord(%this.yKey, 0), getWord(%this.yKey, 1), "joyMoveY", %this);

This is the handling:
function LacrossJMovementControlsBehavior::onUpdate(%this){
	%this.owner.setLinearVelocityX(%this.xMove * %this.speed);
	%this.owner.setLinearVelocityY(%this.yMove * %this.speed);
}

function LacrossJMovementControlsBehavior::joyMoveX(%this, %val){
	if ($pref::Input::Deadzone < %val | - $pref::Input::Deadzone > %val){
		%this.xMove = %val * $pref::Input::Sensitivity; 
		echo("X: " @ %this.xMove);
	}  
	else  
	{  
		%this.xMove = 0;  
	}
//	%this.owner.setPlayerImage(%this.xMove, %this.yMove);
}

function LacrossJMovementControlsBehavior::joyMoveY(%this, %val){
	if ($pref::Input::Deadzone < %val | - $pref::Input::Deadzone > %val){
		%this.yMove = %val * $pref::Input::Sensitivity; 
		echo("Y: " @ %this.yMove);
	}  
	else  
	{  
		%this.yMove = 0;  
	}
}

It works... sort of.

The only thing is that it's really choppy (my guess is from the spamming of commands every time the joystick is moved just a little bit).

Does anyone know a better way to implement joystick movement?

#1
04/18/2009 (12:55 pm)
Resolved!

Lame mistake :(
Turns out the only thing that was lagging the game was the console trying to echo on every call.

Once I commented out the echos it ran smooth.
#2
04/18/2009 (4:21 pm)
yeah, i use Echoes everytime i need to debug and stuff, but when i get the function working properly and stuff, then i just remove the echoes since i dont need them any longer.

also, its a real bad idea to put echoes in functions that can run a few times per second (it can get really bad if that function is ran every tick).

im glad you found the solution yourself.

laters.