In my billiard game , m showing projection of cue ball on mouse events . Simultaneously i also want to move the billiard stick around the cue ball in the direction of projection on mouse event . How can i do that ?
I have done by calculating slope and some more lengthy stuff .
Just wanted to know, is there an easier way to achieve this.
Comments
1) x,y position of constant distance away from the ball at provided angle
2) angle in which to rotate the stick so it will always be directed to ball
So lets say your ball is at x1,y1 and mouse is at x2, y2 coordinate.
Calculate a vector
dx = x1-x2
dy = y1-y2
From top of my head:
1) Find a pointX, pointY which, let's say is 100 pixels far from ball on dx,dy vector
2) Find angle of vector
have not tried the code, so may contain errors, but logic should be somewhat correct
More info on similar problems:
http://giderosmobile.com/forum/discussion/2828/new-day-new-problems-rotate-an-physics-object-towards-direction-of-movement/p1
Thanks , i have done something like that and it works . But got stuck to new problem , to hit the cueball with stick i have to pull back stick in that particular line of direction .Dont know how to pull back stick ?
I have seen this kind of behaviour in prismatic joint , but dont know how to apply it here.
Oh yes it was right there . i mean logic