Mouse angles ***
Blitz3D Forums/Blitz3D Programming/Mouse angles ***
| ||
Hi guys, can anyone please tell me the best way to calculate the mouse pointers angle? For example i want to do a simple little golf game, where the player rotates the line around the ball, to set the angle of the shot (via the mouse). I would really appriciate any help with this. Also would it be possible to include a small example with it working. Thanks very much guys BLUE |
| ||
use atan2: for a top view: while not keydown(1) if mousehit(1) CameraProject(camera,EntityX(ball),EntityY(ball),entityZ(ball)) ballx#=projectedx#() bally#=projectedy#() angle=atan2(mousex()-ballx, mousey()-bally) rotateentity ball,0,angle,0 force#=2 while force >0 moveentity ball,0,0,force updateworld() renderworld() flip force=force-.1 wend flushmouse() endif renderworld() flip wend |
| ||
Hmmm, i don't know where i'm going wrong here :( can you help me please? Heres my code: Graphics 640,480 SetBuffer BackBuffer() Type ball Field x# Field y# Field vx# Field vy# End Type b.ball=New ball b\x=300 b\y=300 While Not KeyHit(1) ClsColor 0,30,0 Cls a=ATan2(MouseX()-b\x, MouseY()-b\y) Line b\x,b\y,Cos(a),Sin(a) Oval b\x,b\y,10,10,True Flip Wend Thanks jfk BLUE :) |
| ||
Oh, it's 2D? Ok, wait a minute...ClsColor 0,30,0 While Not KeyHit(1) Cls a#=ATan2(MouseX()-b\x, MouseY()-b\y) Line b\x, b\y, b\x+Cos(a)*10, b\y+Sin(a)*10 Oval b\x-5,b\y-5,10,10,True Flip Wend Is that better? |
| ||
Excellent!!!!! Thanks ever so much jfk :) You have really helped me out Thanks again BLUE :) |
| ||
btw you can now use a# to move the ball, something like: if force>0 b\x=b\x+sin(a)*force b\y=b\y+cos(a)*force force=force-.1 endif |