DarkBASIC Professional Help Wiki
Advertisement


This command will set the specified object to automatic collision.

Syntax
AUTOMATIC OBJECT COLLISION Object Number, Radius, Response
Parameters
Object Number

Integer
The object number Radius Float
The objects with automatic collision will use a collision sphere of the specified radius Response Integer
If the response value is set to one, the new position backtracks to the last collision free position when a hit occurs. A value of zero adjusts position for sliding collision

Returns

This command does not return a value.

Description

Automatic collision takes over the task of adjusting the object when it hits another object in the 3D scene. Objects with automatic collision use a collision sphere of the specified radius, ignoring its previous collision shape. If the Response value is set to one, the new position backtracks to the last collision free position when a hit occurs. Spheres and boxes are solid objects, and so collision can only occur when they collide together. When an object is entirely within another object, even though the geometry is not touching, the collision is still valid as the larger object would be a solid construct.

Example Code
sync on : sync rate 60 : hide mouse:cls 0

autocam off

set global collision on

ObjectNumber=1

SecondObject=2

make object sphere ObjectNumber,10

color object ObjectNumber,rgb(0,255,0)

position object ObjectNumber, 0,0,0

make object cone secondObject,10

xrotate object secondObject,90

fix object pivot secondObject

color object SecondObject,rgb(255,0,0)

position object SecondObject, 15,0,0

AUTOMATIC OBJECT COLLISION ObjectNumber,5,1

AUTOMATIC OBJECT COLLISION SecondObject,5,1

AUTOMATIC CAMERA COLLISION 0,40,1,0

while mouseclick()=0

set cursor 0,0

if leftkey()=1 then turn object left SecondObject,1

if rightkey()=1 then turn object right SecondObject,1

if upkey()=1 and OBJECT HIT(SecondObject,0)=0 then move object SecondObject,1

if downkey()=1 and OBJECT HIT(SecondObject,0)=0 then move object SecondObject,-1

if spacekey()=1 then move camera 0,1

if returnkey()=1 then position object SecondObject,15,0,0

if OBJECT COLLISION(SecondObject,0) then print "OBJECT COLLISION"

sync

endwhile

set global collision off

delete object ObjectNumber

delete object SecondObject

end
Advertisement