Neither. Your cursor is always in the centre of the screen, but your mouse may not be depending on how you handle your camera.
I suggest using a raycast in the direction the camera is looking. Sparky's has a good command for that, and it returns the object it's colliding with. Plus, you have control of the reach distance using this method.
rem how far the player can reach
ReachDistance# = 6.0
rem get camera data
x# = camera position x()
y# = camera position y()
z# = camera position z()
ax# = camera angle x()
ay# = camera angle y()
rem rotate starting point (0,0,ReachDistance#) around X axis using a rotation matrix
ny# = 0 - (ReachDistance#*sin(ax#))
nz# = ReachDistance#*cos(ax#)
rem rotate resulting point around Y axis using a rotation matrix
nx# = 0 - (nz#*sin(ay#))
nz# = nz# * cos(ay#)
rem add camera positions for final result
inc nx# , x#
inc ny# , y#
inc nz# , z#
remstart
Maths performed were:
1) Define Starting point A = [0,0,ReachDistance#]
2) NewA = A * Rx(ax)
3) NewNewA = NewA * Ry(ay)
4) EndResult = NewNewA + CameraPosition
/ 1 0 0 \
Rx(a) = | 0 cos(a) -sin(a) |
\ 0 sin(a) cos(a) /
/ cos(a) 0 -sin(a) \
Ry(a) = | 0 1 0 |
\ sin(a) 0 cos(a) /
remend
rem find colliding object
Bock = SC_RayCast( 0 , x# , y# , z# , nx# , ny# , nz# , 0 )
rem block found
if Block > 0
rem do stuff with that block here
endif
Can someone double check my maths?
TheComet