Posted: 3rd Jul 2003 5:45
Sorry about the 404. I was out of town and Comcast just changed my homepage from AT&T. The link is updated and should work again.

-Kensupen
Posted: 3rd Jul 2003 15:42
Thanks Kensupen
Posted: 7th Jul 2003 9:59
here's an upgrade for your code :
for archnukr=1 to 2
gosub _collision
next archnukr

what does it do ? try to set the radius at 18, and then, try to go between a column and a wall, without this upgrade
then, with the upgrade
edit : it fix too the problem with the corners, so you don't need the code for the corners anymore
Posted: 8th Jul 2003 4:52
I think that would slow down the code because it would have to do the entire check system twice. It would solve the extra code I put in, but I think it would be slower. I'll check this out later.

-Kensupen
Posted: 8th Jul 2003 8:42
well, I can't say much. I got 55-60 FPS even after pressing enter

Also, I have only found out how to move backward, strafe left/right.....how do i move forward and how do i look around? I have no idea what you are tlaking about when you say "RMB&SMB"

but, from what i see it looks pretty cool

~PlystirE~
Posted: 8th Jul 2003 13:43
Run by DBPro = 23 FPS (online with open 10 IE windows)

it's Very Very GOOOODDDDDD

if i use more than one model, can it support?

Thank you ^ -^ i like it
Posted: 8th Jul 2003 16:48
Plystire: RMB=Right mouse button and LMB=Left mouse button
Posted: 8th Jul 2003 16:58
kensupen, if you use the for next, I think you don't need anymore the system for hmmm .. then there are two walls, how is it called ? for the corners
you can try to put the code for the corners between a remstart and a remend
Posted: 8th Jul 2003 21:30
KENSUPEN I've been messing with the built-in BSP collision for a few days and it is nowhere near as accurate as your code! It's confirmed my decision to dump BSP and use CShop3 (when it's released) and .X files. I might code an intelligent 3rd person camera (that doesn't go through walls as it follows the main character) I made camera code for BSPs it should work perfectly with the X files and the right kind of level design. Cheers mate!
Posted: 12th Jul 2003 16:05
This is really good. Thanx alot. I made the same for an object. I know everybody can do that but I made it easier. Just copy the code here and paste it into the xcol DBpro source.

+ Code Snippet
`***************************
`.X Model sliding collision
`By Kensupen and Lokidecat
`Nerdsoft Creations (C) 2003
`***************************
`This uses all native DBPro commands to give a user sliding collision
`against ANY .X model to slide on ANY angle. It works almost as good as BSP
`collision, except for height. If you can walk onto an object, it just
`puts you at that height. I might try to advance the code later to give
`a smooth height adjustment.

autocam off
set image colorkey 255,0,255
sync on
srate=60
sync rate srate
color backdrop 0
set camera range 1,5000
set ambient light 75

make object sphere 2,20

`Our cheap level
load object "mslevel.x",1
set object transparency 1,2
dir$=get dir$()
`Height cam is off the ground
charht#=10
`speed to move
spd#=3
`set the radius for collisions
radius#=10.0
`set initial object position
position object 2,0,charht#,0
yrotate object 2,180


`number of checks
`the lower this number is, the more off the collisions will be vs. any rotated object.
`also, the lower the number, the more speed it runs at.
`lowest for rotated collision is 4(non rotated/box collision) max is 360, but 360 is WAAAY slow
`I'd advide is you play with this number to keep with a multiple of 4
checks=8
if checks<4 then checks=4
if checks>360 then checks=360
`width of the angles
angwidth=360/checks
`make arrays for collision data
dim ang#(checks-1,2)
dim sort#(checks-1,2)


do
set cursor 0,0
print "Sync Rate set at ",srate," Press Enter to change"
print "FPS:",screen fps()

if scancode()=0 then hold=0
if returnkey()=1 and hold=0
   hold=1
   if srate=60
      srate=0
   else
      srate=60
   endif
   sync rate srate
endif

`Get initial positions and a revert set
oldx#=object position x(2)
oldz#=object position z(2)
cx#=object position x(2)
cy#=object position y(2)
cz#=object position z(2)
ca#=object angle y(2)


if upkey()=1
   cx#=newxvalue(cx#,ca#,spd#)
   cz#=newzvalue(cz#,ca#,spd#)
   position object 2,cx#,cy#,cz#
endif

if leftkey()=1 then ca#=ca#-2
if rightkey()=1 then ca#=ca#+2
yrotate object 2,ca#

`Show the camera angle
print "Object angle:",object angle y(2)
`The main sliding collision code
gosub _collision
`My code to walk up a ramp if the angle isn't too steep
gosub _ramp
`A just in case reset
if spacekey()=1 then position object 2,0,200,0

`Camera follows the object
posx#=object position x(2)
posy#=object position y(2)
posz#=object position z(2)
angle#=object angle y(2)
set camera to follow posx#,posy#,posz#,angle#,50,posy#+20,30,1
sync
loop

_ramp:
`get positions again
cx#=object position x(2)
cz#=object position z(2)
`Get your old height
oldht#=object position y(2)
`calc new height using intersect object from the old height down charht# units
sub#=intersect object(1,cx#,oldht#,cz#,cx#,oldht#-(charht#*2),cz#)
ht#=(oldht#+charht#)-sub#
if sub#=0 then ht#=charht#
`do some gravity
grav#=grav#-0.25
`if you are going up a ramp
if oldht#+grav#<ht#
   grav#=0.0
   position object 2,cx#,ht#,cz#
else
`if you are falling
   ht#=oldht#+grav#
   position object 2,cx#,ht#,cz#
endif
return

_collision:
`make 72 collision points. You can use more or less, but this number seems to work good.
`These are vectors every 5 degrees from the camera position out.
`They return the distance when they hit an object
for x=0 to checks-1
   chx#=newxvalue(cx#,x*angwidth,1)
   chz#=newzvalue(cz#,x*angwidth,1)
   ang#(x,1)=intersect object(1,cx#,cy#,cz#,chx#,cy#,chz#)
   if ang#(x,1)=0 then ang#(x,1)=999999
   ang#(x,2)=x*angwidth
   sort#(x,1)=ang#(x,1)
   sort#(x,2)=ang#(x,2)
next x

`sort the array to find the closest object and it's degrees
for x=0 to checks-2
for y=x+1 to checks-1
   if ang#(x,1)>ang#(y,1)
      temp#=ang#(x,1)
      temp2#=ang#(x,2)
      ang#(x,1)=ang#(y,1)
      ang#(x,2)=ang#(y,2)
      ang#(y,1)=temp#
      ang#(y,2)=temp2#
   endif
next x
next y
`This is the closest wall and what degrees you would face to see it
print "Angle to closest wall:",ang#(0,2)
print "Distance to that wall:",ang#(0,1)
`find +-90 degrees from the closest one for when you walk into a corner so it doesn't shake
prev=wrapvalue(ang#(0,2)-90)/angwidth
nxt=wrapvalue(ang#(0,2)+90)/angwidth
newd#=radius#-ang#(0,1)
newa#=wrapvalue(ang#(0,2)-180)
newd1#=radius#-sort#(prev,1)
newa1#=wrapvalue(sort#(prev,2)-180)
newd2#=radius#-sort#(nxt,1)
newa2#=wrapvalue(sort#(nxt,2)-180)
`if you are less than radius from a wall, push you out to 20 from it
if ang#(0,1)<radius# and ang#(0,1)>0.0
   repx#=newxvalue(cx#,newa#,newd#)
   repz#=newzvalue(cz#,newa#,newd#)
   position object 2,repx#,cy#,repz#
endif
cx#=object position x(2)
cz#=object position z(2)
`this is if you are coming into a corner, this pushes you sideways
if sort#(prev,1)<radius# and sort#(prev,1)>0.0
   repx1#=newxvalue(cx#,newa1#,newd1#)
   repz1#=newzvalue(cz#,newa1#,newd1#)
   position object 2,repx1#,cy#,repz1#
endif
cx#=object position x(2)
cz#=object position z(2)
`and the other way. above is left, this is right
if sort#(nxt,1)<radius# and sort#(nxt,1)>0.0
   repx2#=newxvalue(cx#,newa2#,newd2#)
   repz2#=newzvalue(cz#,newa2#,newd2#)
   position object 2,repx2#,cy#,repz2#
endif
return
Posted: 13th Jul 2003 1:20
nice code 3dZmaster the problem is the camera pass the walls. I am trying to make that dont happen #)
Posted: 13th Jul 2003 13:18
Yeah I didn't fix it.
Posted: 13th Jul 2003 21:23
Kensupen:
I'm trying to use this in my racing game and its working pretty good.
But one thing: How could I get the radius so that it would be more like the car. So it would long but not so width. like this:
---------------------------------------------------------------------
l l
l l
l l
l l
l l
l l
l l
l l
l--------------------------------------------------------------------
I need this because now when the car rotates it goes into the wall. Like if it's facing the wall directly. But from the sides it's fine. If I add more radius, then the rotation collision is fine but then the sides react from too far. Damn, That was unclearly said. I thought I had good english, but I think no one will find out what I meant. Well If you do, please answer
Posted: 13th Jul 2003 23:26
Basically this is a circular check. It can't do rectangles. The only way you could do this is to make 4 checks at the corners of the car. To keep the speed up, I'd do 4 checks of 4 angles. That way you could calculate the angle of the car versus the wall using trig. This was meant for FPS games, but it could be adapted.

-Kensupen
Posted: 14th Jul 2003 14:41
Yeah I know this was meant for an FPs game and I think it's great for that. Best code I've ever seen! Now I'm just trying to make it more flexible. Maybe I should try that thing u told. So 4 checks only for every wheel. Thanx.
Posted: 21st Jul 2003 12:15
another thing 3dZmaster in your code the object cant use the ladder
Posted: 27th Jul 2003 18:14
yeah yeah... I know. I didn't try to do anything special. It is just Kensupen's code with couple changes. And for that car game it worked very well! Pretty good car game actually (well, I made it ), but we stuped the project 'cause of the fps... I coulnd't figure any way to make x object act like bsp, so it wouldn't render the unseen parts of the track. 'cause the car and track are so high polys, the fps was somtehing very weird... But It was very cool game... Thanx thousand times to kensupen.
Posted: 27th Jul 2003 22:14
Hey, Kensupen. This runs very slowly in my newest third person game... hmmm... How can I change the number of collision.. Or you said something like that in the rems... "Make 72 collision points. You can change this value, but it seems to work pretty good" or something. So how can I do that? (sorry, little confused 'bout that array stuff)
Posted: 28th Jul 2003 12:55
The lowest this can go with any accuracy is 4 checks. Basically box collision at 0,90,180,270. Just change the code to match the below code. It won't be very accurate, but it should be a bit faster. Intersect Object just isn't as fast as I'd like it to be. <sigh>

`number of checks
`the lower this number is, the more off the collisions will be vs. any rotated object.
`also, the lower the number, the more speed it runs at.
`lowest for rotated collision is 4(non rotated/box collision) max is 360, but 360 is WAAAY slow
`I'd advide is you play with this number to keep with a multiple of 4
checks=4 <<<<<<<<<<<<<<<<<<<<<<<<Change this to 4
if checks<4 then checks=4
if checks>360 then checks=360
`width of the angles
angwidth=360/checks
`make arrays for collision data
dim ang#(checks-1,2)
dim sort#(checks-1,2)

-Kensupen
Posted: 28th Jul 2003 12:59
Another thing you could try, if you feel up to it, is modify the code to use wrapvalue(object angle y(player object)+my check angles) this will give slightly better collision, but you'd have to also modify the code that pushes you away from the non-player object to be the inverse angle of the collision check and maybe +- the player angle y(). I tried to mess with it at first, but I didn't like the results. It was kinda jerky, but more accurate. 4 checks with my original code works great for almost any FPS type game.

-Kensupen