Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / I am so new to this like 2 weeks !! but collision has me foxed

Author
Message
lothlorien
22
Years of Service
User Offline
Joined: 3rd Aug 2003
Location: 1/2 way up a welsh mountain
Posted: 9th Aug 2003 15:17
After a week of thinking Chinese with Russian subtitles would be easier to learn (sorry to those nationals) but I'm thick British.
I now have a simple 3D game up & running I now want to add lots more objects mainly walls. They have been built fine but can't find a way of detecting collision (I know I'M Thick) the original outer walls work just fine. Read the tutorials & book is now dropping apart, but Please is there someone who could explain how you can add collision detection as you build (simply) I would be ever so grateful - every one has to start somewhere - grovel
MiR
22
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Aug 2003 16:07
The method I use is to create a collision box around the main character. MAKE OBJECT COLLISION BOX Object,x1,y1,z1,x2,y2,z2,flag.
Object is the number of the character
x1,y1,z1,x2,y2,z2 define the size of the box. So if you had a character 100 points by 100 by 100 you´d put -50,-50,-50,50,50,50
flag decides wheather you want sliding collision or more acurate collision (I always go for sliding collision)
Then you make a static collision box that covers the walls.
make static collision box x1,y1,z1,x2,y2,z2
x1,y1 and z1 are the positions of the wall minus half the size and
x2,y2,z2 are the positions of the wall minus half the size
(Acording to example 25 anyway)
Then you put this next piece of code in the main loop
if get static collision hit(oldposx#-s#,oldposy#-s#,oldposz#-s#,oldposx#+s#,oldposy#+s#,oldposz#+s#,posx#-s#,posy#-s#,posz#-s#,posx#+s#,posy#+s#,posz#+s#)=1
dec posx#,get static collision x()
dec posy#,get static collision y()
dec posz#,get static collision z()
if get static collision y()<>0.0 then playergrav#=0.0
endif

position object object number,posx#,posy#,posz#

This changes the position of the charater. I hope this helps. You can find an example of it in example 25 in the basic 3D section

Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 9th Aug 2003 16:17
are you using classic or Pro?, is it fps or tps?, to detect collision for objects is no more difficult than

if object hit(playerobj,0)>20 then set_player_to_last_position

where anything above 20 is a wall object, you need to have a set of variables called something like

oldplayerx#
oldplayery#
oldplayerz#

to save the last position you had before the collision, then you set the position to those when you hat anything, that effectivley makes you stop dead when you collide with anything, so that code becomes

if objecthit(playernumber,0)>20
playerx#=oldplayerx#
playery#=oldplayery#
playerz#=oldplayerz#
endif

that would have the effect of stopping you from walking through walls, you just store the old position, move the player, and if you hit the wall objects you get put back to your last position.
if you have Pro then you can use the "automatic object collision" commands with objects as long as they are square/rectangular and have not been rotated, when you are more advanced you can use the static object collision, but get used to normal collision first, slide collision is one of the tricky subjects that they will hopefully sort in P6 for model based levels, but at the moment you need either a dll or you can use intersect object to make your own slide collision pretty easily, (if you need to ask what slide collision is then you aint ready for it just kiddin ) cheers.

Mentor.

lothlorien
22
Years of Service
User Offline
Joined: 3rd Aug 2003
Location: 1/2 way up a welsh mountain
Posted: 9th Aug 2003 18:58
Just skipped thro what was kindly posted - Many Thanks - it was code like that I used (well pinched from sliding collision tutorial) Sadly not DB PRO cos I got this copy of DB off e-bay for £5 + post MORE FOOL THEM any way it was a trial cos I'd tried visual basic in 21 days "pye game" or similar. Got no where til now!!! but this makes lots more sense by most standards my little bit of fun is crap but it is getting there slowly & I think its brill & as I'm not trying to sell it heeee !??? that's all that counts.
Many thanks again - Will work thro these ans. & try again.

Login to post a reply

Server time is: 2026-07-07 03:46:07
Your offset time is: 2026-07-07 03:46:07