Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello I am developing a Pool game, and I've been scratching my head about what formula is needed to implement an animation for the cue stick.

The animation of the cue stick should look as if it's being pulled back, as the user starts to change the amount of power that he/she would like to apply to the ball.

share|improve this question
So, what have you tried? – thedaian Dec 28 '11 at 5:56
Well I was looking at taking the length of the cue stick and finding other points that lie towards the center of the cue stick and easing it towards one of the points outside of the cue stick area, only issue Im really having is letting the cue stick know in wich direction it is turned so it gets pulled back in the correct direction – user12158 Dec 28 '11 at 7:21
If your cue-stick is pointing towards the ball, why do you need to change its direction when pulling it back? Also, is this 2D or 3D? – bummzack Dec 28 '11 at 8:05
Ok, so why do you need to know the direction to pull back the cue-stick? You wrote: "only issue Im really having is letting the cue stick know in wich direction it is turned". If you have the direction already, why is there a problem? – bummzack Dec 28 '11 at 8:28
Glad you figured it out :). Please consider adding your solution as an answer (and later accept that answer), so that other people with a similar problem can find the solution here. – bummzack Dec 30 '11 at 11:20

In pseudo code, and not very pleasant animation, it could be done like this: I don't really know what you mean by "Animation" I assumed it was the cue moving back depending on the power desired.

vector2f starting_position; // Not a local variable, a member variable

mouse_state mouse = get_mouse(); 

// This checks to see if the right button is down
// it is mutually exclusive with the pulling back of the cue
if (mouse.right_button.state == button_state.DOWN && !cue.pulling_back) 
    cue.pulling_back = true;
    starting_position = cue.position; // store the initial position of the cue

// This will move the cue's position back depending on the 
// axis and junk
if (cue.pulling_back)
    // figure out the change in y 
    // or the respected axis of your choice
    cue.position += mouse.position;
    vector2f change = calculate_change(cue.position, starting_position);
    // power modifed based on change
    cue.power = change * (constants);

if (previous_mouse.right_button.state == button_state.DOWN && mouse.right_button.state == button_state.UP
    && cue.pulling_back)

    if (starting_position != cue.position)
        // reset the cue position and fire ball using cue's power, etc
cue.pulling_back = false;

previous_mouse = mouse;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.