Quote: "Oh, disapointingly, Dark Physics raycasting does not work. It doesn't properly always raycast correctly and also can not return the first object hit, but the one with the lowest object #. It's very disapointing as I had to use sparky's for raycasting, which is great, but MUCH slower."
Are you sure? I have not used raycasting that much, but it works for me. At least I have not had any problems returning the lowest object number.
Ninja_Je5us,
Here is the raycasting tutorial that comes with dark physics.
` this is a simple demonstration of ray casting
REM (Removed media)
` set up the program
phy start
autocam off
sync on
sync rate 60
color backdrop 0
position camera 0, 20, -70
rem stripe textures
`load image "stripe5.png",8
`make object sphere 8,400,48,48
`texture object 8,8
`scale object texture 8,6,6
`set object cull 8,0
`load image "stripe6.png",1
` create some objects
make object cube 1, 5
position object 1, 0, 0, 0
phy make rigid body static box 1
make object cube 2, 5
position object 2, -15, 0, 0
phy make rigid body static box 2
make object cube 3, 5
position object 3, 15, 0, 0
phy make rigid body static box 3
make object cube 4, 5
position object 4, 0, 20, 0
make object box 5, 1, 15, 1
position object 5, 0, 15, 0
texture object 4,1
texture object 5,1
` show Dark Physics logo
`load image "logo.png", 100000
`sprite 1, 0, 600 - 60, 100000
` main program loop
do
` display information
set cursor 0, 0
print "This program demonstrates ray casting in action"
print "The ray casting is taking place from the object at the top of the screen"
print "When it hits an object that object turns blue"
print "Use the arrow keys to move the position of the ray cast left and right"
` set all objects to black
for i = 1 to 3
color object i, 0
next i
` get the position of object 4
x# = object position x ( 4 )
y# = object position y ( 4 )
z# = object position z ( 4 )
` cast a ray down
value = phy ray cast all shapes ( x#, y#, z#, 0, -1, 0 )
` if the ray hit something then colour that object blue
if phy get ray cast hit( )= 1
color object phy get ray cast object ( ), rgb ( 0, 0, 255 )
endif
`move the ray cast left
if leftkey ( )
move object left 4, 0.4
move object left 5, 0.4
endif
` mvoe the ray cast right
if rightkey ( )
move object right 4, 0.4
move object right 5, 0.4
endif
` update the simulation and screen
phy update
sync
loop
And here is how to raycast to the object angle.
` this is a simple demonstration of ray casting
` set up the program
phy start
autocam off
sync on
sync rate 60
color backdrop 0
position camera 0, 20, -70
rem stripe textures
`load image "stripe5.png",8
`make object sphere 8,400,48,48
`texture object 8,8
`scale object texture 8,6,6
`set object cull 8,0
`load image "stripe6.png",1
` create some objects
make object cube 1, 5
position object 1, 0, 0, 0
phy make rigid body static box 1
make object cube 2, 5
position object 2, -15, 0, 0
phy make rigid body static box 2
make object cube 3, 5
position object 3, 15, 0, 0
phy make rigid body static box 3
make object cube 4, 5
position object 4, 0, 20, 0
texture object 4,1
make object box 5, 1, 15, 1
Position Object 5, 0, -5, 0
Glue Object To Limb 5,4,0
` show Dark Physics logo
`load image "logo.png", 100000
`sprite 1, 0, 600 - 60, 100000
` main program loop
do
` display information
set cursor 0, 0
print "This program demonstrates ray casting in action"
print "The ray casting is taking place from the object at the top of the screen"
print "When it hits an object that object turns blue"
print "Use the arrow keys to move the position of the ray cast left and right"
Print
Print "Press up or down to roll the object"
` set all objects to black
for i = 1 to 3
color object i, 0
next i
` get the position of object 4
x# = object position x ( 4 )
y# = object position y ( 4 )
z# = object position z ( 4 )
` cast a ray down
```value = phy ray cast all shapes ( x#, y#, z#, 0, -1, 0 )
Rem Code added
move object down 4,1 `<----- Move the object in the direction you want to raycast.
x2# = object position x ( 4 ) - x# `<----- Get all positions.
y2# = object position y ( 4 ) - y#
z2# = object position z ( 4 ) - z#
move object up 4,1 `<----- Move the object back in to the original location.
value = phy ray cast all shapes ( x#, y#, z#, x2#, y2#, z2# ) `Then raycast.
` if the ray hit something then colour that object blue
if phy get ray cast hit( )= 1
color object phy get ray cast object ( ), rgb ( 0, 0, 255 )
endif
`move the ray cast left
if leftkey ( )
move object left 4, 0.4
endif
` mvoe the ray cast right
if rightkey ( )
move object right 4, 0.4
endif
If Upkey()=1
Roll Object Left 4, 1.0
EndIf
If Downkey()=1
Roll Object Right 4, 1.0
EndIf
` update the simulation and screen
phy update
sync
loop
Hope this helps.