|
Keyboard input smoothing
#278448
07/13/09 22:52
07/13/09 22:52
|
Joined: Jul 2008
Posts: 223 Pittsburgh
The_Clyde
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 223
Pittsburgh
|
Add this function into your script to get WASD (or change it for other buttons) input that is smoothed out based on the direction of the input. It interpolates between directions instead of sharply jumping from one to the other for more natural movement.
var inputrot[3];
var inputs[3];
function getWASD()
{
var moving;
var temprot;
inputs[0] = (key_w - key_s) + joy_force.y;
inputs[1] = (key_a - key_d) - joy_force.x;
inputs[2] = 0;
moving = vec_length(inputs);
vec_to_angle(inputs,inputs);
temprot = inputs[0] - inputrot[0];
temprot = cycle(temprot,-180,180);
if(abs(temprot) > 2) inputrot[0] += sign(cycle(minv(temprot,360 - temprot),-180,180)) * time_frame * 20;
vec_set(inputs,nullvector);
if(moving) vec_for_angle(inputs,inputrot);
}
Ideally this function would be called once per frame in the player action. Access the directional input from the global vector "inputs"
|
|
|
Re: Keyboard input smoothing
[Re: The_Clyde]
#278492
07/14/09 07:59
07/14/09 07:59
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Hm, good idea. What are you using it for? What kind of player movement, I mean?
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Keyboard input smoothing
[Re: Germanunkol]
#278530
07/14/09 10:58
07/14/09 10:58
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
User
|
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
From the manual: key_force The smoothed force applied by pressing the cursor keys. But I guess yours is better because you can change smoothing factors. Good job!
|
|
|
Re: Keyboard input smoothing
[Re: the_mehmaster]
#278583
07/14/09 13:59
07/14/09 13:59
|
Joined: Jun 2007
Posts: 152 Norway
Darkyyes
Member
|
Member
Joined: Jun 2007
Posts: 152
Norway
|
Could be useful in strategy games, as I've seen alot of them if they drop to very low fps keyboard input starts to jack up and wont respond properly
New to lite-c and gamestudio in general, thank you for reading. Com, A7 v7.7
|
|
|
|