After having read some of the posts on the forum it appears that ray casting is broken. However, in the vain hope that it's just me making a mistake can some one give some example code on how ray casting is used?
Here's how I'm doing it:
if Controls.Mouse.Fire.Status = 1
`Get position five units in front of camera
pick screen Screen.CentreX,Screen.CentreY,5
Player.LookVector.x = get pick vector x()
Player.LookVector.y = get pick vector y()
Player.LookVector.z = get pick vector z()
`Get length of vector
dist# = GetDist(Player.Position.x,Player.Position.y,Player.Position.z,Player.LookVector.x,Player.LookVector.y,Player.LookVector.z)
`Get camera vector
dec Player.LookVector.x,Player.Position.x
dec Player.LookVector.y,Player.Position.y
dec Player.LookVector.z,Player.Position.z
`Make unit vector
Player.LookVector.x = Player.LookVector.x/dist#
Player.LookVector.y = Player.LookVector.y/dist#
Player.LookVector.z = Player.LookVector.z/dist#
`Cast ray and check for hit
if phy ray cast closest shape(camera position x(), camera position y(), camera position z(), Player.LookVector.x, Player.LookVector.y, Player.LookVector.z) = 1
position object BulletHoles(NextBulletHole),phy get ray cast hit point x(),phy get ray cast hit point y(),phy get ray cast hit point z()
point object BulletHoles(NextBulletHole),object position x(BulletHoles(NextBulletHole)) + phy get ray cast hit normal x(),object position y(BulletHoles(NextBulletHole)) + phy get ray cast hit normal y(),object position z(BulletHoles(NextBulletHole)) + phy get ray cast hit normal z()
inc NextBulletHole,1 : if NextBulletHole>50 then NextBulletHole=1
endif
endif
and the values returned are all zero. I've used Newton physics for some time now and it may be slow but at least it worked!
Thanks,
Broken_Code
[EDIT]
Please excuse my stupidity, the get pick vector commands are already unit vectors (if the distance into the screen is set to 1) and are not (as I thought) global positions. I changed the code to the folowing and it now works fine.
if Controls.Mouse.Fire.Status = 1
`Get position 1 unit in front of camera
pick screen Screen.CentreX,Screen.CentreY,1
Player.LookVector.x = get pick vector x()
Player.LookVector.y = get pick vector y()
Player.LookVector.z = get pick vector z()
`Cast ray and check for hit
if phy ray cast closest shape(camera position x(), camera position y(), camera position z(), Player.LookVector.x, Player.LookVector.y, Player.LookVector.z) = 1
position object BulletHoles(NextBulletHole),phy get ray cast hit point x(),phy get ray cast hit point y(),phy get ray cast hit point z()
point object BulletHoles(NextBulletHole),object position x(BulletHoles(NextBulletHole)) + phy get ray cast hit normal x(),object position y(BulletHoles(NextBulletHole)) + phy get ray cast hit normal y(),object position z(BulletHoles(NextBulletHole)) + phy get ray cast hit normal z()
inc NextBulletHole,1 : if NextBulletHole>50 then NextBulletHole=1
endif
endif
Sorry for the useless thread.
Broken_Code