key down and ball speed

Game Editor comments and discussion.

key down and ball speed

Postby Arzach » Wed Feb 07, 2007 8:24 pm

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?
Arzach
 
Posts: 2
Joined: Wed Feb 07, 2007 7:32 pm
Score: 0 Give a positive score

Postby morcior » Wed Feb 07, 2007 8:59 pm

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.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Arzach » Wed Feb 07, 2007 11:55 pm

hi morcior,

thank you so much, it's working :)
Arzach
 
Posts: 2
Joined: Wed Feb 07, 2007 7:32 pm
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron