(AGK version: 108.24)
Submitted: 2014-12-15 17:23:49
// this example should work with AGK V1 and AGK V2

// use the ws key or the on screen joystick to move the sphere
// if the sphere cast intersects the box, the box will turn red
// the green and red sphere are cosmetic so you can see where the start and end of the sphere cast is

// set a radius for the sphere cast
radius# = 20.0

// make a box (this will automatically be position at 0,0,0)
CreateObjectBox(1,50,1,50)
SetObjectCollisionMode(1,1)

// make a green sphere that will have the same radius as the sphere cast and position it
CreateObjectSphere(2,radius#*2,12,12)
SetObjectColor(2,0,255,0,255)
SetObjectPosition(2,-50,0,50)

// make a red sphere that will have the same radius as the sphere cast
CreateObjectSphere(3,radius#*2,12,12)
SetObjectColor(3,255,0,0,255)
SetObjectPosition(3,50,0,50)

// create a directional light
CreateLightDirectional(1,-1,-1,0,255,255,255)

// position and orientate camera
SetCameraPosition(1,0,200,0)
SetCameraLookAt(1,0,0,0,0)

// main loop
do

	// get player input
	joystick_y# = GetJoyStickY()*-1

	// move the sphere
	MoveObjectLocalZ(2,joystick_y#)
	MoveObjectLocalZ(3,joystick_y#)

	// use the spheres to determine the start (old) and end (new) points of the sphere cast
	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 ObjectSphereCast(1,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#,radius#) = 0
		// if the box is not intersected by the sphere cast then color it white
		SetObjectColor(1,255,255,255,255)
	else
		// if the box is intersected by the sphere cast then color it red
		SetObjectColor(1,255,0,0,255)
	endif


	sync()

loop
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.