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.

DarkBASIC Discussion / need help

Author
Message
vulcan
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 20th Nov 2006 23:59
ok, i am currently making a 3rd person game and i was wandering if there is a way to create a box and when the 3rd person model i am using runs into it it will move or roll if it is a sphere
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 21st Nov 2006 02:51
I can probably help if you give more information. What do you have for the physics so far? Are you using the built in commands with the DarkBASIC program? The most effective method will vary with different things. If you want to see one i started working on for a third person game my team is designing, I've included a zip file with the script and executable.

Attachments

Login to view attachments
vulcan
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 21st Nov 2006 05:22
if u want i can give you the code, but so far i have loaded an animated object that walks and i have created boxes for floors,walls, ect. And used the "make object collision box" command for the collision. The camera is in 3rd person veiw and you use the mouse to rotate the camera around the object. I am using and use 'W" to move the object forward and 'S' for backward, 'A' to rotate it left and 'D' to ratate it right. When you click the left mouse button it makes the object jump, so i have put gravity in. I think thats about all i've done so far
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 22nd Nov 2006 16:11
In my game, I performed collision checks for major points on the boxes, and then, based on the location of collision points, set the box to drop or flip or whatever. But another way would be to check for the players collision with the object using the get object collision command, and if one is occuring you push the box a certain number of units away from the character. You would have to put this before your collision check and after the player movement step for each loop.

From what I can tell, you are attempting to make a third person platform style game. I would suggest using Sparky's collision DLL as it allows for an easy implementation of things like stairs or ramps that would allow the character to walk up them and jagged cliffs or corners that would require alot of collision boxes.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 22nd Nov 2006 16:26
autocam off : sync rate 60
hide mouse : sync on

rem Make four walls
make object box 1,10,200,1000 : position object 1,-500,100,0 : color object 1,rgb(155,40,20)
make object box 2,10,200,1000 : position object 2, 500,100,0 : color object 2,rgb(155,40,20)
make object box 3,1000,200,10 : position object 3, 0,100,-500 : color object 3,rgb(155,40,20)
make object box 4,1000,200,10 : position object 4, 0,100, 500 : color object 4,rgb(155,40,20)

rem Make a floor and create texture for it
make object box 5,1000,10,1000 : position object 5,0,-5,0 : color object 5,rgb(0,255,0)
create bitmap 1,32,32 : cls rgb(0,155,0) : ink rgb(0,145,0),0 : box 4,4,12,12
get image 1,0,0,32,32 : delete bitmap 1 : texture object 5,1
scale object texture 5,200,200

rem Make a pedestal steps
for t=0 to 4
make object box 6+t,50,8,50
position object 6+t,0,4+(t*10),100+(t*50)
color object 6+t,rgb(100,200,100)
next t

rem Make a player object (and a non-rotated collision box for it)
make object cylinder 11,10
position object 11,0,0,0
color object 11,rgb(20,100,255)
make object collision box 11,-5,-5,-5,5,5,5,0
disable object zdepth 11

rem Make the pedastal use non-rotated box collision
for t=0 to 4
make object collision box 6+t,-25,-4,-25,25,4,25,0
next t

make object box 12,25,25,25
position object 12,100,0,12.5
make object collision box 12,-12.5,-12.5,-12.5,12.5,12.5,12.5,0

rem Make the wall and floor objects into static objects (for auto-camera collision)
for t=1 to 5
make static object t
objx#=object position x(t)
objy#=object position y(t)
objz#=object position z(t)
objsx#=object size x(t)/2.0
objsy#=object size y(t)/2.0
objsz#=object size z(t)/2.0
make static collision box objx#-objsx#,objy#-objsy#,objz#-objsz#,objx#+objsx#,objy#+objsy#,objz#+objsz#
delete object t
next t

rem Make sky black
color backdrop 0

rem Start off player gravity
playergrav#=2.0

rem Main loop
do

rem User prompts
ink rgb(255,255,0),0
center text 320,2,"SHOWS OBJECT SLIDING COLLISION AND CAMERA FOLLOW COMMANDS"
center text 320,20,"USE ARROWS TO MOVE AND SPACE TO JUMP"

rem Store old positions
oldposx#=object position x(11)
oldposy#=object position y(11)
oldposz#=object position z(11)

rem Control player object
if upkey()=1 then move object 11,2
if downkey()=1 then move object 11,-2
if leftkey()=1 then yrotate object 11,wrapvalue(object angle y(11)-3)
if rightkey()=1 then yrotate object 11,wrapvalue(object angle y(11)+3)
if spacekey()=1 and playergrav#=0.0 then playergrav#=2.0

rem Get current object position
posx#=object position x(11)
posy#=object position y(11)
posz#=object position z(11)

rem Handle a touch of gravity
playergrav#=playergrav#-0.1
posy#=posy#+playergrav#

rem Handle sliding collision for player object with other objects
position object 11,posx#,posy#,posz#
if object collision(11,12)>0
boxx#=object position x(12)
boxy#=object position y(12)
boxz#=object position z(12)
if posx#>boxx#+12.5
position object 12,boxx#-1,boxy#,boxz#
endif
if posx#<boxx#-12.5
position object 12,boxx#+1,boxy#,boxz#
endif
if posz#>boxz#+12.5
position object 12,boxx#,boxy#,boxz#-1
endif
if posz#<boxz#-12.5
position object 12,boxx#,boxy#,boxz#+1
endif
endif
if object collision(11,0)>0
dec posx#,get object collision x()
dec posy#,get object collision y()
dec posz#,get object collision z()
playergrav#=0.0
endif

rem Set a size for the player object
s#=object size y(11)/2.0

rem Ensure camera stays out of static collision boxes
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

rem Update with new object position
position object 11,posx#,posy#,posz#

rem Use camera tracker to follow player object
angle#=object angle y(11)
camdist#=25.0 : camhigh#=posy#+10.0 : camfade#=3.5
set camera to follow posx#,posy#,posz#,angle#,camdist#,camhigh#,camfade#,1

rem Tilt camera down a little
xrotate camera 15

rem For fun, slightly move pedastal step
move object 10,0.01

rem Update screen
sync

rem End loop
loop

rem Restore object if ever leave this loop
enable object zdepth 11


here is some script for a box push function. You would later need to add gravity and set up a function to check for collisions with walls like in the download I posted, but it gives you an idea of what it should look like. For a sphere you would need to set the object to be pushed at the y-angle of the player, and not just perform 4 checks like with a box, but one in which the sphere moves in the direction of the player.
vulcan
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 22nd Nov 2006 17:41
alright, thanx
i'll try it out and let you know if i have any more trouble
vulcan
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 23rd Nov 2006 07:16
ok, im still new at this but i tried the code you gave me and it worked but i tried to put it into the game i am currently making and it did not work

here is what i have:

sync on
sync rate 30

` load images
load image "metal_crackle.bmp",1
load image "GRASS09.BMP",2
load image "plate_rusted.bmp",3
load image "power_modual.bmp",4
load image "catwalks.bmp",5
load image "metal.jpg",6

` setup
autocam off : sync rate 60
hide mouse : sync on

` Make a pedestal steps
make object box 1,1000,10,1000
position object 1,1500,-55,500
texture object 1,2

make object box 2,1000,10,1000
position object 2,500,-55,500
texture object 2,1
scroll object texture 2,-10.0,-10.0


` top floor
make object box 3,1000,10,900
position object 3,500,100,550
texture object 3,1
scale object texture 3,-5.0,-5.0

` stairs
make object box 4,100,10,100
position object 4,50,100,50
texture object 4,5

make object box 5,100,10,100
position object 5,150,80,50
texture object 5,5

make object box 17,100,10,100
position object 17,250,60,50
texture object 17,5
make object collision box 17,-50,-5,-50,50,5,50,0

make object box 18,100,10,100
position object 18,350,40,50
texture object 18,5
make object collision box 18,-50,-5,-50,50,5,50,0

make object box 19,100,10,100
position object 19,450,20,50
texture object 19,5
make object collision box 19,-50,-5,-50,50,5,50,0

make object box 20,100,10,100
position object 20,550,0,50
texture object 20,5
make object collision box 20,-50,-5,-50,50,5,50,0

make object box 21,100,10,100
position object 21,650,-20,50
texture object 21,5
make object collision box 21,-50,-5,-50,50,5,50,0

make object box 22,100,10,100
position object 22,750,-40,50
texture object 22,5
make object collision box 22,-50,-5,-50,50,5,50,0

` make windows
make object box 6,12,50,50
position object 6,1000,200,250


` Make three walls to create one with an opening for a door
make object box 7,13,500,500
position object 7,1000,200,250
texture object 7,3
make object collision box 7,-5,-250,-250,5,250,250,0
scale object texture 7,-3.0,-1.0

make object box 8,13,360,110
position object 8,1000,270,550
texture object 8,3
make object collision box 8,-10,-180,-55,10,180,55,0

make object box 9,13,500,400
position object 9,1000,200,800
texture object 9,3
make object collision box 9,-10,-250,-200,10,250,200,0
scale object texture 9,-3.0,-1.0

`Make edging for door
make object box 28,13,150,13
position object 28,1000,23,506
texture object 28,6
make object collision box 28,-7.5,-75,-7.5,7.5,75,7.5,0

make object box 29,13,150,13
position object 29,1000,23,593
texture object 29,6
make object collision box 29,-7.5,-75,-7.5,7.5,75,7.5,0

make object box 30,13,13,75
position object 30,1000,89,550
texture object 30,6
make object collision box 30,-7.5,-7.5,-37.5,7.5,7.5,37.5,0

` make more walls
make object box 10,1000,500,13
position object 10,500,200,1000
texture object 10,3
make object collision box 10,-500,-250,-10,500,250,10,0
scale object texture 10,-3.0,-1.0

make object box 12,1000,500,13
position object 12,500,200,0
texture object 12,3
make object collision box 12,-500,-250,-10,500,250,10,0
scale object texture 12,-3.0,-1.0

make object box 13,13,500,1000
position object 13,0,200,500
texture object 13,3
make object collision box 13,-10,-250,-500,10,250,500,0
scale object texture 13,-3.0,-1.0

make object box 14,1000,1000,13
position object 14,500,450,500
xrotate object 14,90
texture object 14,3
scale object texture 14,-3.0,-1.0

` make floor
make object box 15,990,10,990
position object 15,500,-55,500
texture object 15,1
scroll object texture 15,-10.0,-10.0
make object collision box 15,-485,-5,-485,485,5,485,0

` make outside
make object box 16,1000,10,1000
position object 16,1500,-55,500
texture object 16,2
` Make mor floors
make object box 23,1000,10,1000
position object 23,2500,-55,50
texture object 23,2
make object collision box 23,-500,-5,-500,500,5,500,0

make object box 24,1000,10,1000
position object 24,2500,-55,1050
texture object 24,2
make object collision box 24,-500,-5,-500,500,5,500,0

make object box 25,1000,10,1000
position object 25,1500,-55,1500
texture object 25,2
make object collision box 25,-500,-5,-500,500,5,500,0

make object box 26,1000,500,10
position object 26,1500,200,2000
texture object 26,3
make object collision box 26,-500,-250,-5,500,250,5,0

` Make Moveable box
make object box 27,100,100,50
position object 27,300,158,300
texture object 27,4
make object collision box 27,-50,-50,-25,50,50,25,0

` Make a player object
` load player
load object "idle.x",11
load object "walk.x",11
scale object 11,25,100,25
texture object 11,1
load object "walk.x",11
append object animation "D:\Program Files\Dark Basic Software\Dark Basic\media\models\animated\samurai","D:\Program Files\Dark Basic Software\Dark Basic\media\models\animated\samurai.idle.x",11,100
append object animation "D:\Program Files\Dark Basic Software\Dark Basic\media\models\animated\samurai","D:\Program Files\Dark Basic Software\Dark Basic\media\models\animated\samurai.walk.x",11,10
loop object 11,0,100 : set object speed 11,10
position object 11,150,200,100
make object collision box 11,-5,-2,-5,5,2,5,0

` Make the pedastal use non-rotated box collision
make object collision box 1,-500,-5,-500,500,5,500,0

make object collision box 3,-500,-5,-450,500,5,450,0

make object collision box 2,-500,-5,-500,500,5,500,0

make object collision box 4,-50,-5,-50,50,5,50,0

make object collision box 5,-50,-5,-50,50,5,50,0

` initiate calues
jump#=2
playergrav#=2.0
angle#=0
time#=0
time2#=0

` main loop
do


set text to bold
set cursor 317,50
PRINT "+"
` increment/decrement timers
time#=time#+1
if mouseclick()=0 then timer#=0
` store old positions
oldposx#=object position x(11)
oldposy#=object position y(11)
oldposz#=object position z(11)

` control player object

if keystate(42)=1 then strafe#=1 else strafe#=0

if keystate(32)=1 and strafe#=0 then yrotate object 11,wrapvalue(object angle y(11)+3)
if keystate(30)=1 and strafe#=0 then yrotate object 11,wrapvalue(object angle y(11)-3)
if strafe#=1 then yrotate object 11,cya#
if keystate(32)=1 and strafe#=1

posx#=posx#+cos(cya#/-1)
posz#=posz#+sin(cya#/-1)
position object 11,posx#,posy#,posz#
endif
if keystate(30)=1 and strafe#=1
posx#=posx#-cos(cya#/-1)
posz#=posz#-sin(cya#/-1)
position object 11,posx#,posy#,posz#
endif
if keystate(17)=1 then move object 11,-1.2 : stage=1
if keystate(31)=1 then move object 11,1.2 : stage=1
if mouseclick()=1 and jump#=2 and timer#=0
time2#=time#
playergrav#=2
jump#=jump#-1
jump2#=1
timer#=1
endif
if mouseclick()=0 then jump2#=0
if jump2#=1 and mouseclick()=1 and time#>time2#+25 then playergrav#=-.5
if mouseclick()=1 and jump#=1 and time#>time2#+20 and jump2#=0
time2#=time#
playergrav#=1.0
jump#=jump#-1
jump2#=1
timer#=1
endif

` Store Object angle Y in aY#
AngleY# = object angle Y(11)

If Upkey()=1 then Move object 11,-1 : stage=1

If Leftkey()=1 then Yrotate object 11,Wrapvalue(AngleY#-5)
If Rightkey()=1 then Yrotate object 11,Wrapvalue(AngleY#+5)

if downkey()=1 then move object 11,1 : stage=1

` if character action changes
IF stage=oldstage
IF stage=0
set object frame 11,0.0
loop object 11,4,25
set object speed 11,10
ENDIF
IF stage=1
set object frame 11,0.0
loop object 11,0,10
set object speed 11,10
ENDIF
oldstage=stage
ENDIF

` Get current object position
posx#=object position x(11)
posy#=object position y(11)
posz#=object position z(11)

` increase gravity
playergrav#=playergrav#-0.08
posy#=posy#+playergrav#

` handle sliding collision for ratchet object with other objects
position object 11,posx#,posy#,posz#
if object collision(11,0)>0
objnum#=object collision(11,0)
dec posx#,get object collision x()
dec posz#,get object collision z()
if posy#-5>object position y(objnum#)
dec posy#,get object collision y()
playergrav#=0
jump#=2
jump2#=0
endif
if posy#-5<object position y(objnum#)-(object size y(objnum#)/2.0)
playergrav#=-0.1
dec posy#,get object collision y()
endif
endif

` set a size for the player object (temp)
s#=object size y(11)/2.0

` check for static collisions x&z
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 posz#,get static collision z()
endif

` check for static collisions down
if get static collision hit(oldposx#-s#,oldposy#-s#,oldposz#-s#,oldposx#+s#,oldposy#+s#,oldposz#+s#,posx#-s#+2,posy#-s#,posz#-s#+2,posx#+s#-2,posy#,posz#+s#-2)=1
dec posy#,get static collision y()
playergrav#=0
jump#=2
jump2#=0
endif

` check for static collisions up
if get static collision hit(oldposx#-s#,oldposy#,oldposz#-s#+1,oldposx#+s#,oldposy#+s#,oldposz#+s#,posx#-s#+2,posy#,posz#-s#+2,posx#+s#-2,posy#+s#,posz#+s#-2)=1
posy#=posy#+get static collision y()
playergrav#=-2
endif

` Update with new object position
position object 11,posx#,posy#,posz#

remstart
rem Control Camera
cya#=wrapvalue(cya#+(mousemovex()/3.0))
cxa#=cxa#+(mousemovey()/3.0)
if cxa#<-45.0 then cxa#=-45.0
if cxa#>45.0 then cxa#=45.0
cx#=newxvalue(x#,cya#,sin(cxa#)*10)
cz#=newzvalue(z#,cya#,sin(cxa#)*10)
rotate camera wrapvalue(cxa#),cya#,0
remend

` control camera
cya#=wrapvalue(cya#-(mousemovex()/5.0))
angle#=wrapvalue(angle#-(mousemovey()/3.0))
if angle#>180 then angle#=0
if angle#>80 and angle#<180 then angle#=80
camdist#=cos(angle#)*180
camhigh#=posy#+100+sin(angle#)*90
camfade#=3.5
point camera posx#,posy#+5,posz#
set camera to follow posx#,posy#+5,posz#,cya#,camdist#,camhigh#,camfade#,1



` Handle sliding collision for player object with other objects
position object 11,posx#,posy#,posz#
if object collision(11,27)>0
posx#=object position x(27)
posy#=object position y(27)
posz#=object position z(27)
if posx#>posx#+25
position object 27,posx#+1,posy#,posz#
endif
if posx#<boxx#-25
position object 27,posx#-1,posy#,posz#
endif
if posz#>posz#+25
position object 27,posx#,posy#,posz#+1
endif
if posz#<posz#-25
position object 27,posx#,posy#,posz#-1
endif
endif
if object collision(11,0)>0
dec posx#,get object collision x()
dec posy#,get object collision y()
dec posz#,get object collision z()
playergrav#=0.0
endif



` Ensure camera stays out of static collision boxes
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

` Update with new object position
position object 11,posx#,posy#,posz#

` update screen
sync

` end loop
loop

for t=1 to 26
make static object t
objx#=object position x(t)
objy#=object position y(t)
objz#=object position z(t)
objsx#=object size x(t)/2.0
objsy#=object size y(t)/2.0
objsz#=object size z(t)/2.0
make static collision box objx#-objsx#,objy#-objsy#,objz#-objsz#,objx#+objsx#,objy#+objsy#,objz#+objsz#
delete object t
next t



is there anything i have done wrong or placed in the wrong place? And if so, what
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 23rd Nov 2006 21:06
There were quite a few things wrong with your program. The first is that your box collision check is in the wrong place. It needs to be before the collision check for normal objects or the player will just be pushed away before the loop checks for the collision there. The second is that you never actually check for the updated position of the box and use variables that will just be zero.

I also noticed that most of your script appears to consist of segments of code cut and pasted from two different programs I wrote and posted on the codebase. You should try actually looking through some tutorials and trying to understand whats really happening in these types of games before you start a major program or you will get confused later on.

Another suggestion is using for/next commands in you world creation if you absolutely have to do them in BASIC (their primitives polygon counts are very high). The for/next command works like a mini loop that runs a certain number of times through using a new variable value for each loop.

EXAMPLE:

for x=1 to 5
make object box x,50,10,50
texture object 5,3
position object x,50,10*x,10+(5*x)
next
vulcan
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 24th Nov 2006 02:23
alright, thanx

i decided to start my game over by creating all the code by myself and look back at others just for reference, cuz the one i was working on was, like you said, mostly just cutting and pasting codes. And i didn't understand much of it because i didn't actually read through and look to see what each part of the code did

if i stil lhave problems with the moving a box function, i will let you know

Login to post a reply

Server time is: 2025-05-27 19:31:19
Your offset time is: 2025-05-27 19:31:19