Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 1,086 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Keyboard input smoothing #278448
07/13/09 22:52
07/13/09 22:52
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline 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.

Code:
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 Offline
Expert
Germanunkol  Offline
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 Offline
User
the_mehmaster  Offline
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
From the manual:
Quote:
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
D
Darkyyes Offline
Member
Darkyyes  Offline
Member
D

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
Re: Keyboard input smoothing [Re: Darkyyes] #278584
07/14/09 14:01
07/14/09 14:01
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
It could be useful for my project, thanks laugh.

Re: Keyboard input smoothing [Re: the_mehmaster] #278585
07/14/09 14:04
07/14/09 14:04
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
Even better is that it lets you use WASD instead of the cursos keys!

I was also going for rotational smoothing, similar to what you'd get from joystick input. Because only eight directions can come from the WASD keys, I use this function to add the in-between directions.

I'm using this for a third-person action game, my Supercat project. It's not evident in any of the videos though, because I only just improved my getWASD() function yesterday.

Re: Keyboard input smoothing [Re: The_Clyde] #278587
07/14/09 14:07
07/14/09 14:07
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline
Serious User
VeT  Offline
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Code:
temprot = cycle(temprot,-180,180);



Looking like ang() do the same, but a little bit shorter smile


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Keyboard input smoothing [Re: VeT] #278623
07/14/09 19:53
07/14/09 19:53
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
Yes, I noticed ang() in the manual earlier today. It would do exactly that but it didn't occur to me that it would exist as a separate function! laugh


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1