phy ray cast all shapes
phy ray cast closest shape
phy ray cast
All of these commands does not work correctly.
We are either a very rough result of either the ITS WRONG OR NOT AT ALL AT ALL.
`%ProjectTitle%
`======================
`©%Author%
`======================
`Main Source File
set display mode 1024,768,32
PHY START
PHY SET GRAVITY 0,-9.8,0
randomize timer()
sync on
sync rate 60
GLOBAL Ideal#
GLOBAL Diff#
GLOBAL FrameX#
global jumpST
global jumptime
GLOBAL DIM FrameLast(1)
GLOBAL McLi
global oldmcli
GLOBAL MX
GLOBAL my
GLOBAL mMX
GLOBAL mMy
GLOBAL mMz
global shftKEY
SC_setMaxCollisions 100
global group
group=0
//make object box 900,1650,20,140
//position object 900,1093,510,1718
//PHY MAKE RIGID BODY static box 900
make object box 999,2999,10,1199
position object 999,2000,5,1000
PHY MAKE RIGID BODY static box 999
SC_setupObject 999,group,0
make object box 901,3480,220,200
position object 901,2000,110,1700
PHY MAKE RIGID BODY static box 901
SC_setupObject 901,group,0
make object box 902,3480,220,200
position object 902,2000,110,300
PHY MAKE RIGID BODY static box 902
SC_setupObject 902,group,0
make object box 903,200,220,1200
position object 903,3600,110,1000
PHY MAKE RIGID BODY static box 903
SC_setupObject 903,group,0
make object box 904,200,220,1200
position object 904,400,110,1000
PHY MAKE RIGID BODY static box 904
SC_setupObject 904,group,0
make object box 905,500,20,100
position object 905,2245,347,1750
PHY MAKE RIGID BODY static box 905
PHY set RIGID BODY rotation 905,0,0,-44
PHY set RIGID BODY position 905,2245,347,1750
SC_setupObject 905,group,0
SC_updateObject 905
make object box 906,100,10,1600
position object 906,2000,505,1000
PHY MAKE RIGID BODY static box 906
SC_setupObject 906,group,0
make object box 907,500,20,100
position object 907,1755,347,250
PHY MAKE RIGID BODY static box 907
PHY set RIGID BODY rotation 907,0,0,44
PHY set RIGID BODY position 907,1755,347,250
SC_setupObject 907,group,0
SC_updateObject 907
makecharacter()
FrameTimer_Reset()
do
`phy set fixed timing 0.2*FrameX#
FrameTimer()
` IF RND(50)=10 THEN color light 1,10,10,RND(255)
McLi=MOUSECLICK()
MX=MOUSEX()
my=MOUSEY()
mMX=MOUSEMOVEX()
mMy=MOUSEMOVEY()
mMz=MOUSEMOVEZ()
shftKEY=SHIFTKEY()
//// ` cast a ray down
x# = object position x ( 2000 )
y# = object position y ( 2000 )
z# = object position z ( 2000 )
value = phy ray cast all shapes( x#, y#, z#, 0, -1, 0 )
value2b =PHY GET RAY CAST hit ( )
if value2b=1
dstph3b#=PHY GET RAY CAST DISTANCE ( )
endif
text 100,80,str$(dstph3b#)
value = phy ray cast closest shape( x#, y#, z#,0, -1, 0)
value2a =PHY GET RAY CAST hit ( )
if value2a=1
dstph3a#=PHY GET RAY CAST DISTANCE ( )
endif
text 100,100,str$(dstph3a#)
value3 = phy ray cast( x#, y#, z#,x#, y#-5000, z#,0 )
value2 =PHY GET RAY CAST hit ( )
if value2=1
dstph3#=PHY GET RAY CAST DISTANCE ( )
endif
text 100,120,str$(dstph3#)
//text 100,100,str$(value)
//text 100,120,str$(dstph3#)
//text 100,140,str$(value3)
numOfCols=SC_multipleRayCast(0,x#,y#,z# ,x#,y#-5000.0,z#,0)
dst#=50000
if numOfCols>0
for i=0 to numOfCols-1
newx#=SC_getStaticCollisionX(i)
newy#=SC_getStaticCollisionY(i)
newz#=SC_getStaticCollisionZ(i)
normx#=SC_getCollisionNormalX(i)
normy#=SC_getCollisionNormalY(i)
normz#=SC_getCollisionNormalZ(i)
dist#=SC_getCollisionDistance(i)
objhit=SC_getObjectHit(i)
if dist#<dst# then dst#=dist#
next i
endif
text 0,300,"sc_collision distance-"+str$(dst#)
if keystate(57)=1 and dst# < 65 and jumpST=0
jumpST=1:jumptime=timer()
endif
if jumpST=1 then jump(200/FrameX#)
key = 0
position camera object position x ( 2000 ), object position y ( 2000 ) + 10, object position z ( 2000 )
rotate camera object angle x ( 2000 ), object angle y ( 2000 ), object angle z ( 2000 )
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = wrapvalue ( CameraAngleY# + mmx * 0.1 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mmy * 0.1 )
yrotate object 2000, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate object 2000, curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
msp=200/FrameX#
if shiftkey()=1 then msp=msp*2
if upkey ( ) or keystate(17)=1
key = 1
phy move character controller 2000, msp
endif
if downkey ( ) or keystate(31)=1
key = 1
phy move character controller 2000, -msp
endif
if leftkey ( ) or keystate(30)=1
yrotate object 2000, object angle y ( 2000 )+90
phy move character controller 2000, -msp
yrotate object 2000, object angle y ( 2000 )-90
key = 1
endif
if rightkey ( ) or keystate(32)=1
yrotate object 2000, object angle y ( 2000 )-90
phy move character controller 2000, -msp
yrotate object 2000, object angle y ( 2000 )+90
key = 1
endif
in = inlestn()
if dst# > 55.19 and in = 0 and jumpST=0
phy move character controller 2000, FrameX#
phy move character controller 2000, -FrameX#
endif
phy update
sync
loop
Function FrameTimer()
Diff# = ABS(Timer() - FrameLast(0))
Ideal# = 1000.0 / 60.0
FrameX# = Diff# / Ideal#
If Diff# > 1000 then FrameX# = 0
FrameLast(0) = Timer()
EndFunction
Function FrameTimer_Reset()
FrameLast(0) = Timer()
EndFunction
function makecharacter()
` create our box controller
make object box 2000, 15, 78, 15
position object 2000,400, 300, 400
YROTATE CAMERA 180
phy make CAPSULE character controller 2000, 400, 300, 400, 15, 80, 1, 20, 75.0
hide object 2000
YROTATE OBJECT 2000,180
endfunction
function inlestn()
inzone=0
x1#=object position x(2000)
y1#=object position y(2000)
z1#=object position z(2000)
if x1#>780 and x1#<840 and z1#>380 and z1#<425 and y1#>0 and y1#<300
inzone=1
endif
if x1#>3155 and x1#<3215 and z1#>380 and z1#<425 and y1#>0 and y1#<300
inzone=1
endif
if x1#>3155 and x1#<3215 and z1#>1570 and z1#<1620 and y1#>0 and y1#<300
inzone=1
endif
if x1#>780 and x1#<840 and z1#>1570 and z1#<1620 and y1#>0 and y1#<300
inzone=1
endif
endfunction inzone
function jump(msp)
xa#=object angle x ( 2000 )
xrotate object 2000, -90
phy move character controller 2000, msp*3
xrotate object 2000, xa#
if jumptime+250<timer() then jumpST=0
endfunction
delete memblock 1
All this is very strange.
On RAY CAST influence even visual overlap of objects that RAY is not even intersect.
EDIT:
All problem in CHARACTER CONTROLLER !!!
Certainly not with him, but with the object of which is connected Character controller.
`%ProjectTitle%
`======================
`©%Author%
`======================
`Main Source File
set display mode 1024,768,32
PHY START
PHY SET GRAVITY 0,-9.8,0
randomize timer()
sync on
sync rate 60
GLOBAL Ideal#
GLOBAL Diff#
GLOBAL FrameX#
global jumpST
global jumptime
GLOBAL DIM FrameLast(1)
GLOBAL McLi
global oldmcli
GLOBAL MX
GLOBAL my
GLOBAL mMX
GLOBAL mMy
GLOBAL mMz
global shftKEY
SC_setMaxCollisions 100
global group
group=0
GLOBAL n_McLi AS INTEGER : `nav
GLOBAL n_MX AS INTEGER : `nav
GLOBAL n_my AS INTEGER : `nav
GLOBAL n_mMX AS INTEGER : `nav
GLOBAL n_mMy AS INTEGER : `nav
GLOBAL n_mMz AS INTEGER : `nav
GLOBAL n_CamDist# AS FLOAT : `nav
GLOBAL n_selobj AS INTEGER : `nav
GLOBAL n_qqq# AS DOUBLE FLOAT : `nav
GLOBAL n_selobjX# AS DOUBLE FLOAT : `nav
GLOBAL n_selobjy# AS DOUBLE FLOAT : `nav
GLOBAL n_selobjz# AS DOUBLE FLOAT : `nav
GLOBAL n_PointObj : `nav
GLOBAL n_newCamDist# : `nav
GLOBAL n_mc : `nav
GLOBAL n_mc4DubleNot : `nav
GLOBAL n_mc4Duble : `nav
GLOBAL n_mc4DubleTime : `nav
GLOBAL n_mc2Duble : `nav
GLOBAL n_dist# : `nav
GLOBAL n_speed# : `nav
GLOBAL n_uskor# : `nav
GLOBAL n_dx# : `nav
GLOBAL n_dy# : `nav
GLOBAL n_dz# : `nav
GLOBAL OLDCDIST# : `nav
GLOBAL n_FirstRun : `nav
n_FirstRun = 1
n_PointObj = 5000000
MAKE OBJECT SPHERE n_PointObj , 0.05 , 32 , 32:HIDE OBJECT n_PointObj
POSITION OBJECT n_PointObj , 1000 , 1000 , 1000
XROTATE CAMERA 35
yROTATE CAMERA 45
n_selobjX# = 700
n_selobjy# = 150
n_selobjz# = 700
n_newCamDist# = 300.0
make object box 999,2999,10,1199
position object 999,2000,5,1000
PHY MAKE RIGID BODY static box 999
SC_setupObject 999,group,0
make object box 901,3480,220,200
position object 901,2000,110,1700
PHY MAKE RIGID BODY static box 901
SC_setupObject 901,group,0
make object box 902,3480,220,200
position object 902,2000,110,300
PHY MAKE RIGID BODY static box 902
SC_setupObject 902,group,0
make object box 903,200,220,1200
position object 903,3600,110,1000
PHY MAKE RIGID BODY static box 903
SC_setupObject 903,group,0
make object box 904,200,220,1200
position object 904,400,110,1000
PHY MAKE RIGID BODY static box 904
SC_setupObject 904,group,0
make object box 905,500,20,100
position object 905,2245,347,1750
PHY MAKE RIGID BODY static box 905
PHY set RIGID BODY rotation 905,0,0,-44
PHY set RIGID BODY position 905,2245,347,1750
SC_setupObject 905,group,0
SC_updateObject 905
make object box 906,100,10,1600
position object 906,2000,505,1000
PHY MAKE RIGID BODY static box 906
SC_setupObject 906,group,0
make object box 907,500,20,100
position object 907,1755,347,250
PHY MAKE RIGID BODY static box 907
PHY set RIGID BODY rotation 907,0,0,44
PHY set RIGID BODY position 907,1755,347,250
SC_setupObject 907,group,0
SC_updateObject 907
do
McLi=MOUSECLICK()
MX=MOUSEX()
my=MOUSEY()
mMX=MOUSEMOVEX()
mMy=MOUSEMOVEY()
mMz=MOUSEMOVEZ()
shftKEY=SHIFTKEY()
//// ` cast a ray down
x# = camera position x ( 0 )
y# = camera position y ( 0 )
z# = camera position z ( 0 )
value = phy ray cast all shapes( x#, y#, z#, 0, -1, 0 )
value2b =PHY GET RAY CAST hit ( )
if value2b=1
dstph3b#=PHY GET RAY CAST DISTANCE ( )
endif
text 100,80,str$(dstph3b#)
value = phy ray cast closest shape( x#, y#, z#,0, -1, 0)
dstph3a#=PHY GET RAY CAST DISTANCE ( )
text 100,100,str$(dstph3a#)
value3 = phy ray cast( x#, y#, z#,x#,y#-5000.0,z#,2 )
value2 =PHY GET RAY CAST hit ( )
if value2=1
dstph3#=PHY GET RAY CAST DISTANCE ( )
endif
text 100,120,str$(dstph3#)
numOfCols=SC_multipleRayCast(0,x#,y#,z# ,x#,y#-5000.0,z#,0)
dst#=50000
if numOfCols>0
for i=0 to numOfCols-1
newx#=SC_getStaticCollisionX(i)
newy#=SC_getStaticCollisionY(i)
newz#=SC_getStaticCollisionZ(i)
normx#=SC_getCollisionNormalX(i)
normy#=SC_getCollisionNormalY(i)
normz#=SC_getCollisionNormalZ(i)
dist#=SC_getCollisionDistance(i)
objhit=SC_getObjectHit(i)
if dist#<dst# then dst#=dist#
next i
endif
text 0,300,"sc_collision distance-"+str$(dst#)
gosub look
phy update
sync
loop
`this line is never executed but we must include it so that DBPro
`knows to include the memblock commands into the exe (the dll uses them)
delete memblock 1
look:
`SET CURRENT CAMERA 0
n_mc = McLi
n_MX = MX
n_my = my
n_mMX = mMX
n_mMy = mMy
n_mMz = mMz / 120
IF n_mc = 0
CHANGE MOUSE 2
ENDIF
IF n_mMz <> 0
IF n_mMz > 0 THEN DEC n_newCamDist# , n_newCamDist# / 2.0 : IF n_newCamDist# < 0.1 THEN n_newCamDist# = 0.1
IF n_mMz < 0 THEN INC n_newCamDist# , n_newCamDist# / 2.0 : IF n_newCamDist# >666000 THEN n_newCamDist# = 666000
ENDIF
IF KEYSTATE(29)=1
IF KEYSTATE(78)=1
DEC n_newCamDist# , n_newCamDist# / 1.3 : IF n_newCamDist# < 0.1 THEN n_newCamDist# = 0.1
ENDIF
IF KEYSTATE(74)
INC n_newCamDist# , n_newCamDist# / 1.3 : IF n_newCamDist# >666000 THEN n_newCamDist# = 666000
ENDIF
ENDIF
IF n_mc = 2
CHANGE MOUSE 3
IF n_mc4Duble = 0
n_mc4Duble = 1
IF n_mc4DubleTime < TIMER() - 400
n_mc4DubleTime = TIMER()
ELSE
n_selobj = PICK OBJECT(n_MX , n_my , 1 , 100)
IF n_selobj <> 0
n_selobjX# = GET PICK VECTOR X()+CAMERA POSITION X()
n_selobjy# = GET PICK VECTOR Y()+CAMERA POSITION Y()
n_selobjz# = GET PICK VECTOR Z()+CAMERA POSITION Z()
POSITION OBJECT n_PointObj ,n_selobjX# ,n_selobjy#,n_selobjz#
ENDIF
ENDIF
ENDIF
ELSE
n_mc4Duble = 0: n_mc4DubleNot = 0
ENDIF
IF n_mc = 4 OR KEYSTATE(29)=1
position mouse screen width()/2,screen height()/2
CHANGE MOUSE 4
POSITION CAMERA OBJECT POSITION X(n_PointObj) , OBJECT POSITION Y(n_PointObj) , OBJECT POSITION Z(n_PointObj)
YROTATE CAMERA (CAMERA ANGLE Y() + n_mMX/2.0)
XROTATE CAMERA (CAMERA ANGLE X() + n_mMy/2.0)
MOVE CAMERA -n_CamDist#
ELSE
n_mc2Duble = 0
ENDIF
IF ABS(n_CamDist#-n_newCamDist#) > 0.1
IF n_CamDist#-n_newCamDist# < 0
INC n_CamDist# , ABS(n_CamDist#-n_newCamDist#) / 20.0
ELSE
DEC n_CamDist# , ABS(n_CamDist#-n_newCamDist#) / 20.0
ENDIF
ENDIF
IF SCANCODE() <> 0
n_qqq# = n_CamDist# / 100.0
SET OBJECT TO CAMERA ORIENTATION n_PointObj
ROTATE OBJECT n_PointObj , 180 , OBJECT ANGLE Y(n_PointObj) , OBJECT ANGLE Z(n_PointObj)
IF KEYSTATE(17) OR KEYSTATE(200)
MOVE OBJECT n_PointObj , -n_qqq#
ENDIF
IF KEYSTATE(31) OR KEYSTATE(208)
MOVE OBJECT n_PointObj , n_qqq#
ENDIF
IF KEYSTATE(30) OR KEYSTATE(203)
MOVE OBJECT LEFT n_PointObj , n_qqq#
ENDIF
IF KEYSTATE(32) OR KEYSTATE(205)
MOVE OBJECT RIGHT n_PointObj , n_qqq#
ENDIF
IF KEYSTATE(33)
MOVE OBJECT UP n_PointObj , n_qqq#
ENDIF
IF KEYSTATE(18)
MOVE OBJECT UP n_PointObj , -n_qqq#
ENDIF
n_selobjX# = OBJECT POSITION X(n_PointObj)
n_selobjy# = OBJECT POSITION Y(n_PointObj)
n_selobjz# = OBJECT POSITION Z(n_PointObj)
ENDIF
n_dx# = n_selobjX# - OBJECT POSITION X(n_PointObj)
n_dy# = n_selobjy# - OBJECT POSITION Y(n_PointObj)
n_dz# = n_selobjz# - OBJECT POSITION Z(n_PointObj)
n_dist# = SQRT((n_dx#*n_dx#)+(n_dy#*n_dy#)+(n_dz#*n_dz#))
IF n_dist# > 0.1
POINT OBJECT n_PointObj , n_selobjX# , n_selobjy# , n_selobjz#
IF n_speed# < n_dist# / 30.0 THEN INC n_speed# , n_uskor# ; INC n_uskor# , 0.03 ; ELSE n_speed# = n_dist# / 10.0 ; n_uskor# = 0
MOVE OBJECT n_PointObj , n_speed#
ENDIF
POSITION CAMERA OBJECT POSITION X(n_PointObj) , OBJECT POSITION Y(n_PointObj) , OBJECT POSITION Z(n_PointObj)
MOVE CAMERA -n_CamDist#
IF n_CamDist#<>OLDCDIST#
OLDCDIST#=n_CamDist#
ENDIF
RETURN
.....already beside..... for all