// this example should work in AGK V1 and V2
// use the ws keys or the on screen joystick to move the green and blue spheres up and down
// if the ray cast intersects the spinning box then a blue sphere will show the intesect point
// make a transparent box and rotate it so it stands on its corner (will be position at 0,0,0 automatically)
CreateObjectBox(1,20,30,20)
SetObjectTransparency(1,1)
SetObjectColor(1,255,255,255,100)
SetObjectRotation(1,45,45,0)
// create a blue sphere to use as a marker object (this will show the position of the ray cast intersect)
CreateObjectSphere(2,5,12,12)
SetObjectColor(2,0,0,255,255)
// create a green sphere to show the start point of the ray cast
CreateObjectSphere(3,5,12,12)
SetObjectColor(3,0,255,0,255)
SetObjectPosition(3,-20,45,-20)
// create a red sphere to show the start point of the ray cast
CreateObjectSphere(4,5,12,12)
SetObjectColor(4,255,0,0,255)
SetObjectPosition(4,20,45,20)
// Create a directional light
CreateLightDirectional(1,1,-1,0.5,255,255,255)
// Position and orientate camera
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)
// main loop
do
// get player input
joystick_y# = GetJoystickY()*-1
// move green and red spheres
MoveObjectLocalY(3,joystick_y#)
MoveObjectLocalY(4,joystick_y#)
// rotate the box
RotateObjectGlobalY(1,0.5)
// raycast from the green sphere to the red sphere
old_x# = GetObjectX(3)
old_y# = GetObjectY(3)
old_z# = GetObjectZ(3)
new_x# = GetObjectX(4)
new_y# = GetObjectY(4)
new_z# = GetObjectZ(4)
object_hit = ObjectRayCast(1,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#)
print(object_hit)
// ray cast against object 1 only
if object_hit <> 0
// get the ray cast intersect point
intersect_x# = GetObjectRayCastX(0)
intersect_y# = GetObjectRayCastY(0)
intersect_z# = GetObjectRayCastZ(0)
// set the position of the blue sphere to the intersect point
SetObjectPosition(2,intersect_x#,intersect_y#,intersect_z#)
// make the blue sphere visible
SetObjectVisible(2,1)
else
// if the ray cast does not intersect the box then hide the blue sphere
SetObjectVisible(2,0)
endif
sync()
loop
Help make AGK better by submitting an example for this command! (All examples are subject to approval)