Game Development Community

Input problem

by Steven Hine · in Torque Game Builder · 05/17/2008 (4:47 pm) · 11 replies

Here's the problem I'm having:

When pressing up + left to move diagonally, a third button press wil not register. It does work for all other diagonal directions.

Any ideas??

#1
05/17/2008 (4:52 pm)
I think it depends on the computer. My laptop dont even register up + left or down + right, so I cant really play my games on it without getting frustrated. It works just fine on my other computers though.
#2
05/17/2008 (4:55 pm)
He is right... My iMac registers up to 4 buttons, but nothing more...
#3
05/17/2008 (5:50 pm)
I should have put in that I am using a behavior to detect input. I did change the keys with all directions working. Then moved to a different computer and more keys had problems... using "space" as attack and arrows for movement. The problem is only when you are moving diagonally. (i.e. three button presses at the same time) This must be a clitch of some sort.

I'm guessing because the code does work with arrows and the "a" key for attacking that it should work with "space".

Interesting problem...
#4
05/17/2008 (10:17 pm)
I've used arrow keys and X for fire in my games without problem. I suspect it's just a bug in your control logic.
#5
05/18/2008 (6:00 am)
I thought it was too, but when I use "a" to attack and the arrow keys everything works correctly.
#6
05/18/2008 (12:21 pm)
That sounds like a keyboard limitation, ( and a common one ), not much TGB can do about it.
#7
05/18/2008 (1:24 pm)
You may consider posting your moveMap code along with the called functions just to validate the logic, but I suspect it is a hardware limitation as well...

If you have a USB gamepad that you can map out to the same actions and it works, then you can test to see if you have the same issues/limitations with a device designed not to have them.
#8
05/19/2008 (11:02 am)
Yes, this is a common keyboard limitation, and it varies depending on what keyboard you have.

The traditional solution is to use modifier keys (shift, options, control, etc.) as much as possible, as most keyboards will support any two normal keys AND any additional modifier keys, all at once, with no problems.

The problem is, with Torque, modifier keys aren't supported (in terms of being able to be detected individually) on OS X. On Windows you can do it, but not on the Mac. I personally have modified the source code, however, on the Mac to support this. It's not a perfect solution, but it works well enough for my own needs.
#9
05/19/2008 (2:27 pm)
I have modified the platformer behavior for my project:
if(!isObject(platformerControlsBehavior))
{
   %template = new BehaviorTemplate(platformerControlsBehavior);
   
   %template.friendlyName = "RPG Controls";
   %template.behaviorType = "Input";
   %template.description  = "Movement control RPG";
   
   %template.addBehaviorField(leftKey, "Key to bind to left movement", keybind, "Left");
   %template.addBehaviorField(rightKey, "Key to bind to right movement", keybind, "Right");
   %template.addBehaviorField(upKey, "Key to bind to up movement", keybind, "Up");
   %template.addBehaviorField(downKey, "Key to bind to down movement", keybind, "Down");
   %template.addBehaviorField(attackKey, "Key to bind to attack", keybind, "Attack");
   
   %template.addBehaviorField(runSpeed, "Speed when moving", float, 60.0);
   
}

function platformerControlsBehavior::onBehaviorAdd(%this)
{
   if (!isObject(moveMap))
      return;
   
   // bind our keys on the keyboard
   moveMap.bindObj(getWord(%this.attackKey, 0), getWord(%this.attackKey, 1), "attack", %this);
   moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveLeft", %this);
   moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "moveRight", %this);
   moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "moveUp", %this);
   moveMap.bindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), "moveDown", %this);

   %this.left = 0;
   %this.right = 0;
   %this.up = 0;
   %this.down = 0; 
   %this.attack = 0;
	
	// Enable the update callback.
	%this.owner.enableUpdateCallback();
	
	// Set some collision stuffs.
	%this.owner.setCollisionMaxIterations(2);
}

// It appears that these are called once every tick...?
function platformerControlsBehavior::attack(%this, %val)
{
   %this.owner.attack();
     
}

function platformerControlsBehavior::moveLeft(%this, %val)
{
   %this.left = %val;
}

function platformerControlsBehavior::moveRight(%this, %val)
{
   %this.right = %val;
}

function platformerControlsBehavior::moveUp(%this, %val)
{
   %this.up = %val;
}

function platformerControlsBehavior::moveDown(%this, %val)
{
   %this.down = %val;
}

function platformerControlsBehavior::OnUpdate(%this)
{
	%this.updateHorizontal();
	%this.updateVertical();
	%this.setCurrentAnimation();
	
}

// Called by onUpdate().
function platformerControlsBehavior::updateHorizontal(%this)
{
   // figure out what speed in what direction we are moving based on key input
	%newSpeed = (%this.right - %this.left) * %this.runSpeed;
   %this.owner.setLinearVelocityX(%newSpeed);
	
}

// Called by onUpdate().
function platformerControlsBehavior::updateVertical(%this)
{
	// figure out what speed in what direction we are moving based on key input
	%newSpeed = (%this.down - %this.up) * %this.runSpeed;
   %this.owner.setLinearVelocityY(%newSpeed);

}

// Called by onUpdate().
function platformerControlsBehavior::setCurrentAnimation(%this)
{
   %this.owner.setCurrentAnimation();
}
-------------------------------------
I'd like to give the user the option to choose any keys they would like to use. The easiest way around this problem is to use a click type of movement like Warcraft III.
#10
05/19/2008 (4:10 pm)
I may change the movement to point and click.
#11
05/20/2008 (11:15 am)
@Steven:
you should use the "Code" tags when posting source code, so that its more readable...