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 Professional Discussion / How to make gravity

Author
Message
Li Sama
14
Years of Service
User Offline
Joined: 20th Mar 2012
Location:
Posted: 20th Mar 2012 16:47
Hello, I am currently a High School student trying to learn the attributes of programming in DarkBasic Professional. I am usuing a previous demo called the LTType demo and I was wondering if anyone could help me with some problem solving.
I am trying to make gravity, but I am unsure if my matrix (the passing landscape) even has a true collision box.

[rem Create landscape
load image "U:\Projects\LTypeDemo\media\ground\desrt.bmp",1
make matrix 1,3000,1500,15,15
prepare matrix texture 1,1,1,1
position matrix 1,-750,-300,0
gosub _newmatrix
Is the current landscape. How would I give it a collision box?
My other question would be how to make gravity.
Rem Player Character
load object "U:\Projects\LTypeDemo\media\ship\monkey.x", 101
scale object 101,100,150,200
position object 101,150,100,0
make object collision box 101,-25,-35,-25,25,35,25,0
load image "U:\Projects\LTypeDemo\media\ship\monkey fur.jpg", 77
texture object 101,0, 77
That is the current main character and the actual mobility controls would be
if upkey()=1 and sx#<350.0 then iy#=6.0 :
if downkey()=1 then iy#=-6.0 : lift=2
if leftkey()=1 and sx#>-450.0 then ix#=-6.0
if rightkey()=1 and sx#<450.0 then ix#=6.0
if spacekey ()= 1 then p1y# = p1y# + mypower
ix#=ix#/1.2 : iy#=iy#/1.2
syx#=sx#+ix# : sy#=sy#+iy#
position object 101,p1x#,p1y#,500
So basically my main questions would be how to make a collision box for a randomly generated matrix and how to create gravity when I get this collision working (if possible).

To innovate the world.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Mar 2012 23:56
Quote: "So basically my main questions would be how to make a collision box for a randomly generated matrix and how to create gravity when I get this collision working (if possible)."


Well, a collision box on a matrix may not be necessary depending on what you are trying to achieve. You can detect collision with a matrix by using GET GROUND HEIGHT. That will return the height of the matrix (landscape) at any X,Z location.

So if your character was located at (10,25,40) somewhere on the matrix, then you can find how high the ground is at that location with



Once you have that height at that location, you can reposition your objects or character accordingly. It can also give you information if something is falling and going to hit the ground. The position of impact would be the X,Z location and the Y would be the ground height.

As far as gravity, there are a couple of ways to do it. Basically, you change the Y value of an object until it reaches a limit (like the ground height, or zero).




Enjoy your day.
thecartm
14
Years of Service
User Offline
Joined: 30th Mar 2012
Location: In your closet, hiding....
Posted: 31st Mar 2012 00:40
This is how to do the gravity.
gravityvariable = 0 ' making the variables
height = 0
fall = 0
DO ' just put these lines in the script
height = OBJECT POSITION Y -object#here- ' traces the height
if height >= -groundheighthere- + fall' if you are above the ground
if fall <= 5 ' and if fall is below 5
if fall >= 0 ' and is not negative somehow
fall = fall + 1 ' fall slightly faster
ENDIF ' continue
endif ' still continue
if fall <= 9 ' if you fell for just a little
if fall > 5 ' if you fell for long enough
fall = fall + 2 ' fall a bit faster
ENDIF ' continue
endif
if fall <= 21 ' if you fell under maxspeed
if fall > 9 ' but still fell for a while
fall = fall + 3 ' fall faster
ENDIF ' continue
endif
else ' If you are at ground level
fall = 0 ' stop falling
endif ' done that lengthy chunk
position object -object#here-,xhere,height - fall,zhere ' fall.
WAIT wait time here
loop ' repeat again
This lets you fall and speed up. Alter it anyway you like. The if fall <= 21 line is to limit maxspeed. The numbers clunk wierd to even out falling. Now I have a hedache from coding. Enjoy.

Hah, my signature is meaningless.

Login to post a reply

Server time is: 2026-07-09 20:56:03
Your offset time is: 2026-07-09 20:56:03