Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Smooth Movement on Keyboard Input

pete
Registered User
Quote
2011-06-03 11:34:15

Hi

From tutorial 2 I know how to handle keyboard inputs but if you hold down F or G you will notice that the box makes a short break after the first move. Just like when you are holding down a key in a texteditor, there is a short delay before it starts repeating. Now I wonder how you can create smooth movements on keyboard inputs like the FPS camera.


pete
Registered User
Quote
2011-06-03 22:07:18

i solved it by creating a boolean that gets true by "on key down" and false by "on key up"


niko
Moderator
Quote
2011-06-04 07:30:20

Yes, that's the way it should be done. :)


actarus
Registered User
Quote
2012-01-20 16:38:56

Have you got an example of how to smooth it?
I d'ont see exactly how to use the boolean :/


actarus
Registered User
Quote
2012-01-20 17:08:55

Ok, I've found a way to do it.
Here is the code for 3 keys :


var IsKeyLeftPressed = false;
var IsKeyRightPressed = false;
var IsKeyUpPressed = false;

engine.OnAnimate = function()
{
if (IsKeyLeftPressed) {cam.Pos.X += 5;}
if (IsKeyRightPressed) {cam.Pos.X -= 5;}
if (IsKeyUpPressed) {cam.Pos.Y += 5;}
}


document. = function(event)
{
if (event.keyCode == 39) IsKeyRightPressed = false;
if (event.keyCode == 37) IsKeyLeftPressed = false;
if (event.keyCode == 38) IsKeyUpPressed = false;
}
document. = function(event)
{
if (event.keyCode == 39) IsKeyRightPressed = true;
if (event.keyCode == 37) IsKeyLeftPressed = true;
if (event.keyCode == 38) IsKeyUpPressed = true;
}



warner
Registered User
Quote
2012-01-21 20:20:32

The forum seems to remove certain words from the code. "on key down" and "on key up" are dissapeared from the code.


mushra
Registered User
Quote
2012-02-21 17:38:58

I have implemented this setup in my game, but if I am pressing and holding w to walk and I press another button without releasing w first, and then release the second button pressed and the w, the keyreleased function for w is not fired. I have to press w again to stop it.
This happens with all my keys,

Any ideas as to why this is happening/how to solve it.

Thanks.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact