First of all, make a timer-based loop
dim check_distance(65500)
b = 100
c = 200
do
inc distance_timer
if distance_timer = 60
distance_timer = 0
for a = b to c
if sqrt((object position x(a)-camera position x()^2)+(object position z(a)-camera position z()^2)) < 500.0
check_distance(a)=1
else
check_distance(a)=0
endif
next a
endif
sync
loop
This will make an array called "check_distance", when an object comes closer than 500.0 units it will set "check_distance(object)" to "1".
Now, you only need to check collision for objects that are close (check_distance(object)=1)
if upkey()=1
position camera camera position x()+sin(camera angle y()),camera position y(),camera position z()
for a = b to c
if check_distance(a)=1
x# = camera position x()
x2# = object position x(a)
y# = camera position y()
y2# = object position y(a)
z# = camera position z()
z2# = object position z(a)
if sqrt((x#-x2#)^2+(y#-y2#)^2+(z#-z2#)^2)) < 10.0
position camera x#-sin(camera angle y()),y#,z#
endif
endif
next a
position camera camera position x(),camera position y(),camera position z()+cos(camera angle y())
for a = b to c
if check_distance(a)=1
x# = camera position x()
x2# = object position x(a)
y# = camera position y()
y2# = object position y(a)
z# = camera position z()
z2# = object position z(a)
if sqrt((x#-x2#)^2+(y#-y2#)^2+(z#-z2#)^2)) < 10.0
position camera x#,y#,z#-cos(camera angle y())
endif
endif
next a
endif
First, the camera is moved using SIN to calculate the new X position, then it checks for math-collision and when it hits something the camera is placed back on its old position. Then the same happens using COS to calculate the new Z position.
This is useful for sliding collision.
For boxes you can use a position check, but I find this one better
Quote: "
UPDATED
Amd 2800+
1024mb pc3200
A7N8X - Deluxe
Ati Radeon 9800PRO 256mb"