(AGK version: 108.19)
Submitted: 2014-02-22 04:25:35
rem
rem AGK Application 108 19
rem

SetDisplayAspect( 4.0/3.0 )

//------------------------------------------

cameraID=1
SetCameraRange( cameraID, 1, 1000 )
SetCameraPosition( cameraID, 0,5,-15 ) //+100
SetCameraLookAt( cameraID, 0, 0, 5, 0 )

//------------------------------------------

dim cube[6]

i=0
for y#=0.0 to 5.0
    obj=CreateObjectBox( 1, 1, 1 )
    SetObjectPosition( obj, 0, 0.5+(y#*1.1), 5 )
    //SetObjectCollisionMode( obj, 0 ) //Off
    SetObjectCollisionMode( obj, 1 ) //On

    SetObjectColor( obj, random(0,255),random(0,255),random(0,255), 192 )

    SetObjectLightMode(obj,1)
    i=i+1
    cube[i]=obj
next

//------------------

do

 Print("hello 3d raycast")

 if 1=1
     ObjectRayCast(0, 0,100,5 , 0,-1,5)
     n=GetObjectRayCastNumHits()
     print("GetObjectRayCastNumHits "+str(n))
     for i=0 to n-1
      obj = GetObjectRayCastHitID(i)
      print("Obj " +str(obj))
      print(GetObjectRayCastY(i))
     next
 endif

 if getpointerpressed()=1
    exit
 endif

 Sync()
loop
end

(AGK version: 108.21)
Submitted: 2014-12-15 08:25:16
// this example should work in AGK V1 and AGK V2

// use the w and s key or the push up and down on the on screen joystick to move the two spheres back and forth
// the cube will turn red if the raycast - from the green sphere to the red sphere - intersects it

// create a box (it will automaticall be located at point 0,0,0)
CreateObjectBox(1,20,20,20)

// create a green sphere and position it
CreateObjectSphere(2,10,12,12)
SetObjectColor(2,0,255,0,255)
SetObjectPosition(2,-50,0,50)

// create a red sphere and position it
CreateObjectSphere(3,10,12,12)
SetObjectColor(3,255,0,0,255)
SetObjectPosition(3,50,0,50)

// create a direction to make the whole scene look better (go on, delete this line and you'll find out why I included it)
CreateLightDirectional(1,-1,-1,-1,255,255,255)

// position and orientate the camera
SetCameraPosition(1,0,150,-60)
SetCameraLookAt(1,0,0,0,0)

// main loop
do

	// get player input (multiply by -1 so sphere move in direction the joystick is pushed, once again delete it and see what happens)
	joystick_y# = GetJoystickY() * -1

	// move the spheres based on input
	MoveObjectLocalZ(2, joystick_y#)
	MoveObjectLocalZ(3, joystick_y#)

	// ray cast from the green sphere to the blue sphere
	old_x# = GetObjectX(2)
	old_y# = GetObjectY(2)
	old_z# = GetObjectZ(2)

	new_x# = GetObjectX(3)
	new_y# = GetObjectY(3)
	new_z# = GetObjectZ(3)

	if ObjectRayCast(1,old_x#,old_y#,old_z# ,new_x#,new_y#,new_z#) = 1
		SetObjectColor(1,255,0,0,255)
	else
		SetObjectColor(1,0,255,0,255)
	endif

	sync()
loop
(AGK version: 2017.05.15)
Submitted: 2017-05-16 09:35:25
rem
rem AGK Application 2017.05.15
rem 3D Shooter decal
rem MR 16.05.2017

rem Landscape App
SetDisplayAspect( 4.0/3.0 )

setdefaultwrapu(0)
setdefaultwrapv(0)

//------------------------------------------ Cam

cameraID=1
SetCameraRange( cameraID, 1, 1000 )
SetCameraPosition( cameraID, 0,2,-10 )
SetCameraLookAt( cameraID, 0, 0, 5, 0 )

//------------------------------------------ Light

SetSunActive(1)
SetSunColor(255, 255, 255)
SetSunDirection(0, -1, 1)

//------------------------------------------ Ground

iGround=CreateObjectBox( 100, 0.01, 100 )
SetObjectCollisionMode( iGround, 1 ) //<<<<
SetObjectColor( iGround, 128,255,128,255 )
SetObjectLightMode(iGround,1)

//------------------------------------------ Cube

iBox=CreateObjectBox( 1, 1, 1 )
SetObjectPosition( iBox, 0, 0.5, 4 ) //+1
SetObjectCollisionMode( iBox, 1 ) //<<<<
SetObjectColor( iBox, 255,255,255,255 )

SetObjectLightMode(iBox,1)

RotateObjectLocalY( iBox, 45 )

//------------------------------------------ Image decal

imgBlood=loadimage("Blood.png")

//------------------------------------------ Scope

imgScope=loadimage("Scope.png")
sprScope=createsprite(imgScope)
setspritesize(sprScope,4,4)

//------------------------------------------

do

 cx#=GetCameraX(1)
 cy#=GetCameray(1)
 cz#=GetCameraz(1)

 mx#=getpointerx()
 my#=getpointery()

 sx#=Get3DVectorXFromScreen(mx#,my#)*1000.0
 sy#=Get3DVectorYFromScreen(mx#,my#)*1000.0
 sz#=Get3DVectorZFromScreen(mx#,my#)*1000.0

 ObjectRayCast(0,cx#,cy#,cz#,sx#,sy#,sz#)
 n=GetObjectRayCastNumHits()
 print(n)
 for i=0 to n-1
  obj = GetObjectRayCastHitID(i)
  x#=GetObjectRayCastx(i)
  y#=GetObjectRayCastY(i)
  z#=GetObjectRayCastz(i)
  nx#=GetObjectRayCastNormalX(i)
  ny#=GetObjectRayCastNormalY(i)
  nz#=GetObjectRayCastNormalZ(i)
  tx#=GetScreenXFrom3D(x#,y#,z#)
  ty#=GetScreenYFrom3D(x#,y#,z#)
  setspritepositionbyoffset(sprScope,tx#,ty#)
 next

 if getpointerpressed()=1
    iBlood=createobjectplane(0.5,0.5)
    SetObjectLightMode(iBlood,1)
    SetObjectPosition(iBlood,x#+nx#*0.1,y#+ny#*0.1,z#+nz#*0.1)
    SetObjectLookAt(iBlood,x#+nx#*1.0,y#+ny#*1.0,z#+nz#*1.0,0)
    SetObjectTransparency( iBlood, 1 )
    setobjectimage(iBlood,imgBlood,0)
    SetObjectCollisionMode( iBlood, 0 ) //<<<<
 endif

 Sync()
loop
end
Help make AGK better by submitting an example for this command!
(All examples are subject to approval)
Login to post an example of your own.