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 / Collisioon and Gravity

Author
Message
banjobob
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Kentucky
Posted: 22nd Jan 2009 01:54
It's been 5 years since I used Db and I wrote this piece of code that don't really work. It's a sphere that the camera follows and the sphere stops when it collides with boxes. The camera flickers for some odd reason and I am wondering how to make the sphere jump on top of the boxes and move on them and jump back off. sorry for the dumb questions.here is the source and I didnt use any media files or anything.thanks

Attachments

Login to view attachments
banjobob
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Kentucky
Posted: 22nd Jan 2009 17:31
Sorry for the dumb questions, I have been up al night but I fugured out a few things. I camera don't flicker and the sphere collision don't jump back and forth. I can now jump on boxes and move across. But there is a new question - the sphere can go through the box when he jumps if it's not totally on top of the box. heres the codesync on
sync rate 0
hide mouse

Make Matrix 1,500,500,50,50
Create Bitmap 1,128,128
CLS RGB(100,2,0)
Get Image 1,0,0,128,128
Set Current Bitmap 0
Delete Bitmap 1
Prepare Matrix Texture 1,1,1,1

Position Matrix 1,0,-5,0

fog on
fog distance 400
make light 1

make camera 1
position camera 1,100,2,100

randomize timer()

I=1

for I=1 to 20
make object cube I,rnd(20)
position object I,rnd(500),get ground height(1,500,500),rnd(500)
color object I,rgb(rnd(255),rnd(255),rnd(255))
set object collision to boxes I
Next


make object sphere 50,10
position object 50,100, 0, 100
set object collision to spheres 50

ypos#=0

do

rem Controlling the Sphere
If Leftkey()=1 Then Yrotate Object 50,Wrapvalue(Object Angle Y(50)-4)
If Rightkey()=1 Then Yrotate Object 50,Wrapvalue(Object Angle Y(50)+4)
if upkey()=1 then move object 50,2
if downkey()=1 then move object 50,-2
if spacekey()=1 then inc ypos#,2
if spacekey()=0 and ypos#>0 and object collision(50,0)=0 then dec ypos#,2


rem Get Spheres Position
xpos#=object position x(50)
rem ypos#=object position y(50)
zpos#=object position z(50)

Rem The sliding collision bit
If Object Collision(50,0)>0 and ypos#=0
Dec XPos#,Get Object Collision X()
rem Dec YPos#,Get Object Collision Y()
Dec ZPos#,Get Object Collision Z()
Endif

Position Object 50,XPos#,YPos#,ZPos#

set camera to follow 1,xpos#,ypos#,zpos#,object angle y(50),60,20,20,0

set cursor 0,0
print "X:",object position x(50)
print "Y:",object position y(50)
print "Z:",object position z(50)

sync
loop
Tom0001
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location:
Posted: 23rd Jan 2009 00:24
banjobob,

Please use code tags for source code. I tested the code and I see your problem with being able to move through boxes in mid-jump. I also note that the jumping has not been finished properly. If you hold down spacebar, the y will continue to increase. Not sure if this is what you wanted or not, but yeah.

Login to post a reply

Server time is: 2024-11-25 12:21:34
Your offset time is: 2024-11-25 12:21:34