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 / Game Framework---Need Help with Collision

Author
Message
Italy Portugal
19
Years of Service
User Offline
Joined: 4th Mar 2005
Location: that depends on your honesty
Posted: 20th Apr 2006 03:56
While writing this game framework, I ran into the problem of sliding collision.
e.g. jumping while running into a wall causes me to hang in the air...

I am using DBPro 5.8 with no enhancement packs.

look around is with mouse,
jump is space bar(this needs to be smoothed out, but I think I know how to do that)
movement is with the wasd keys
Here is the code.

the Media you will have to supply yourself.

Professor: "There is no such thing as absolute truth"
Student: "Is that always true?" "...Well..."
(c)HookWare Games (c) Italy Portugal
Relativity
19
Years of Service
User Offline
Joined: 29th Mar 2005
Location: Position is relative.
Posted: 20th Apr 2006 05:03
Can't see the code (unless you're magic like TDK that SOURCE button doesn't work), but it sounds like using Sparky's .dll for the collision will work well for you.

If you have DBC, check here:
http://darkbasic.thegamecreators.com/?m=codebase_view&i=d71183f50e9a2d3d7dcec986ff7dbd76

DBP? Try here:
http://darkbasic.thegamecreators.com/?m=codebase_view&i=4d2dc9395d6bc9371370eb552e5b18c0
Italy Portugal
19
Years of Service
User Offline
Joined: 4th Mar 2005
Location: that depends on your honesty
Posted: 20th Apr 2006 23:30
Sorry,
here is the code

Rem Project: HookWare
Rem Created: 7/30/2005 9:35:56 PM
Rem Last Modified 3/06/2006
Rem Current Version: DarkBasic Professional 5.8
Rem (c) HookWare Games
Rem (c) Italy Portugal

Rem ***** Main Source File *****

`set up usual for 3D program
SYNC ON: SYNC RATE 60
BACKDROP ON: COLOR BACKDROP 0
AUTOCAM OFF: HIDE MOUSE
`set up basic collision for now
SET GLOBAL COLLISION ON
AUTOMATIC CAMERA COLLISION 0,1.5,1
`position camera
POSITION CAMERA 20,1.6,20
POINT CAMERA 200,50,200
`setup global variables
`jumping() contains jumping indicator and maximum jumping height.
DIM jumping(2)
`height() contains the ground height and player height and height collision
DIM height#(3)
`load media
load_media()
` make landscape
make_world()

`game loop
DO
`control camera
control_camera()

animate_objects()
`print variables
SET CURSOR 0,0
PRINT "position: ", CAMERA POSITION X(0)," ", CAMERA POSITION Y(0)," ", CAMERA POSITION Z(0)
PRINT "angle: ", CAMERA ANGLE X(0)," ", CAMERA ANGLE Y(0)," ", CAMERA ANGLE Z(0)
`update screen
SYNC
LOOP

FUNCTION load_media()
`load matrix texture
LOAD IMAGE "grass_T.BMP",1

`load wall texture
LOAD IMAGE "brick1_T.BMP",2
ENDFUNCTION

FUNCTION make_world()
`make a matrix

MAKE MATRIX 1,10000,10000,200,200
`texture matrix
PREPARE MATRIX TEXTURE 1,1,1,1

`position walls
RESTORE world
FOR y=1 TO 4
`read information
READ number,width#,height#,depth#,x#,y#,z#,texture
`make object
MAKE OBJECT BOX number,width#,height#,depth#
`position object
POSITION OBJECT number,x#,y#,z#
`texture objects
TEXTURE OBJECT number,texture
NEXT y

`-----position lights---------------------------------------------------------------------

`-----position static objects-------------------------------------------------------------

`-----position dynamic objects------------------------------------------------------------

ENDFUNCTION

`***********************************************
`* This function controls the use of the camera*
`***********************************************
FUNCTION control_camera()
`###############################################
`# LIST OF VARIABLES #
`###############################################
`# cx# = camera angle x #
`# cy# = camera angle y #
`# height#(1) = minimum height of the player #
`# height#(2) = current height of the player #
`# height#(3) = previous height of the player #
`# jumping(1) = variable for jumping #
`# jumping(2) = maximum height for jumping #
`# #
`# for more documentation see readme.txt #
`###############################################

`-----This controls the movement of the camera according to the mouse--------------------
ROTATE CAMERA CAMERA ANGLE X(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0

`-----Control player movement------------------------------------------------------------
cx#=camera angle x(0) : cy#=camera angle y(0)
if keystate(17)=1 then xrotate camera 0,0 : move camera 0,0.2 : xrotate camera 0,cx#
if keystate(31)=1 then xrotate camera 0,0 : move camera 0,-0.2 : xrotate camera 0,cx#
if keystate(30)=1 then yrotate camera 0,cy#-90 : move camera 0.2 : yrotate camera 0,cy#
if keystate(32)=1 then yrotate camera 0,cy#+90 : move camera 0.2 : yrotate camera 0,cy#

`-----Make sure that the camera doesn't get to HUGE values when it is rotating------------
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280

`-----make sure that the angle numbers do not exceed 360----------------------------------
yrotate camera 0,wrapvalue(camera angle y(0))

`-----Apply simple gravity to player------------------------------------------------------
`-----Get the minimum height possible for the player-----------------------------------
height#(1)=get ground height(1,camera position x(), camera position z())
`-----get the player's current height--------------------------------------------------
height#(2)=camera position y()
`-----apply the gravity----------------------------------------------------------------
height#(2) = height#(2)-0.1
`-----make sure the camera doesn't got through the matrix------------------------------
if height#(2)<height#(1)+1.5
height#(2)=height#(1)+1.5
endif

`-----time to start jumping--Before we start though, we need to make sure that------------
`-----the player is not already jumping, and has not reached the ground yet---------------
if jumping(1)<2
`-----press spacebar and jump-------------------------------------------------------------
if spacekey()=1
jumping(1)=1
jumping(2)=5
endif
endif

`-----now check if reached maximum height while jumping-----------------------------------
if jumping(1)=1 and height#(2)<jumping(2)
height#(2)=height#(2)+0.16
endif
`-----if above maximum, start dropping----------------------------------------------------
if height#(2)>jumping(2)
jumping(1)=2
endif
`-----when you land reset the jumping variable--------------------------------------------
if height#(2)=1.5
jumping(1)=0
endif
`-----when you land on an object, reset the jumping variable so you can jump off the object
if height#(3)=height#(2) and jumping(1)>0
jumping(1)=0
jumping(2)=jumping(2)+5
endif
`-----update the camera position----------------------------------------------------------
position camera camera position x(),height#(2),camera position z()



` make sure that you do not run off the edge of the matrix
if camera position x()<=0 then position camera 0,height#(2),camera position z()
if camera position x()>=10000 then position camera 10000,height#(2),camera position z()
if camera position z()<=0 then position camera camera position x(),height#(2),0
if camera position z()>=10000 then position camera camera position x(),height#(2),10000
`update the previous height variable
height#(3)=height#(2)
`end the function
ENDFUNCTION

FUNCTION animate_objects()

ENDFUNCTION

`uses boxes
`object number,width,height,depth,x,y,z,texture)
world:
data 1,100,8,1,50,4,99,2
data 2,100,8,1,50,4,1,2
data 3,1,8,100,99,4,50,2
data 4,1,8,100,1,4,50,2
`data 5,
`data 6,
`data 7,
`data 8,


hope this works better

Professor: "There is no such thing as absolute truth"
Student: "Is that always true?" "...Well..."
(c)HookWare Games (c) Italy Portugal
Relativity
19
Years of Service
User Offline
Joined: 29th Mar 2005
Location: Position is relative.
Posted: 21st Apr 2006 00:50
Ah, you're using a matrix. In that case Sparky's .dll won't work. You'll have to use the GET MATRIX HEIGHT command and position your player appropriately. Here are a couple examples from the codebase:

http://darkbasic.thegamecreators.com/?m=codebase_view&i=c69d16a48b427fd9999f6eca4b746d69
http://darkbasic.thegamecreators.com/?m=codebase_view_code&i=b69c37441b1493b2329ec78280e16e05

Also try the tank demo included with the DB examples.
Italy Portugal
19
Years of Service
User Offline
Joined: 4th Mar 2005
Location: that depends on your honesty
Posted: 21st Apr 2006 05:59
Hmmm...
checked it out, nice information...

I just found something else called "versatile sliding collision"

I was planning on moving it from matrix to model..main problem with that was that my ".X" to ".bsp" converter wasn't working...

hopefully this thread will be helpful to someone besides me!

Professor: "There is no such thing as absolute truth"
Student: "Is that always true?" "...Well..."
(c)HookWare Games (c) Italy Portugal
Italy Portugal
19
Years of Service
User Offline
Joined: 4th Mar 2005
Location: that depends on your honesty
Posted: 2nd May 2006 05:00
oops, forgot the link
http://www.thegamecreators.com/?m=codebase_view_code&i=68f23412ed6a0d4f7506c4aca6c672ea

Sorry

Professor: "There is no such thing as absolute truth"
Student: "Is that always true?" "...Well..."
(c)HookWare Games (c) Italy Portugal

Login to post a reply

Server time is: 2024-09-24 21:37:33
Your offset time is: 2024-09-24 21:37:33