Script to make models run using alternating keys.

Posted By: ItsMe

Script to make models run using alternating keys. - 04/30/08 12:13

Im trying to script a model running by tapping the left and right keys,
the faster you tap them the faster they run.
The character must simply run in a straight line.

Hopefully this is possible?

If anybody could lend me a land, please post =]


Posted By: Joozey

Re: Script to make models run using alternating keys. - 04/30/08 13:21

you'd need to make a function that checks how long it takes to press, release and press a key. I think this will do, but haven't checked it. Use run_speed to move your character.

 Code:
var tap_counter;
var run_speed;

...

while (1) {
  
  if (key_cur || key_cul) {
    tap_counter = 0;
    
    while (key_cur || key_cul) { wait(1); } //wait for the key to be released
    while (!key_cur && !key_cul) { tap_counter += 1 * time_step; wait(1); } //wait for the key to be pressed again, activate counter
    
    run_speed = (key_cur - key_cul) * (1/tap_counter); //calculate direction and multiply by the 'slowness' of pressing key
  }
  
  wait(1);
}

Posted By: DLively

Re: Script to make models run using alternating keys. - 05/14/08 00:27

Wow, very efficient...


well done. Thanks for sharing this.


Devon.
© 2023 lite-C Forums