Page 1 of 1

key down and ball speed

PostPosted: Wed Feb 07, 2007 8:24 pm
by Arzach
hi,

I'm working on a game, but I have faced a problem I couldn't solve by myself. If you can help, I'll be very glad.

Problem is below:
I have a ball in my game and the game is based on throwing the game. I want the ball to be thrown to a distance controlled by the keypress duration.
For example when the "Space" key is been pressed and hold the ball will thrown to a longer distance, if less hold, to a shorter distance.

like a pinball ball. :P

Is there someone who can help me about it?

PostPosted: Wed Feb 07, 2007 8:59 pm
by morcior
make key down and key up events on the view actor for the spacebar - both script editor actions.

make a global variable called "ballForce"

on the key down event, write code like

Code: Select all
ballForce = 10; // initial force of the ball

CreateTimer("view", "spacetimer", 100); // i guessed this line of code so look up the correct syntax in the script reference, or even easier use the "functions" button at the bottom of the script window to make the createtimer code for you.


on the key up event write code like
Code: Select all
DestroyTimer("spacetimer");
ball.angle = 90; // angle you want the ball to shoot at
ball.directional_velocity = ballForce; // set the ball moving


finally, now you've created a timer you can make a "timer" event on the view actor, and pick a script editor action:

Code: Select all
ballForce += 1; // amount to increase the balls force each nth of a second the spacebar is held


i think that should do it! the timer you create should be on the view actor, a periodic timer that repeats every 100ms or so, and infinite.

PostPosted: Wed Feb 07, 2007 11:55 pm
by Arzach
hi morcior,

thank you so much, it's working :)