Hi, Ive been working on some jumping and collision code in DBPro with some simple cone and cube objects. Its not finished (Havent put in any collision on the z axis nor is there a limit on how far you can jump upwards) but I have come across a problem i am unable to solve.
Here it is:
As you can see, the collision of the cube is all wrong. It is colliding
in the object, not
on as it should.
Anyway, here is my code:
sync on : sync rate 60 : hide mouse
make object cone 1, 12
color object 1, rgb(0,0,255)
make object cube 2,12
color object 2, rgb(255,0,0)
object1y=0
object1x=0
object1z=50
object2y=object1y-object size (1)*1.6
object2x=0
object2z=50
gravity=0
jump=0
walkspeed=1
do
position object 2,object2x,object2y,object2z
position object 1,object1x,object1y,object1z
jumpheight=object size(1)+100
if upkey()=1 then object1z=object1z+walkspeed
if downkey()=1 then object1z=object1z-walkspeed
if rightkey()=1 then object1x=object1x+walkspeed
if leftkey()=1 then object1x=object1x-walkspeed
if spacekey()=1 then jump=1
if jump=1 then gosub jump
object1y=object1y-gravity
if gravity >= 1 then gravity = 0
gravity=gravity+1
if object collision (1,2)
if object position x(2) + object size x(2) < object position x(1) + 1 then object1x = object1x + 1
if object position x(2) + 1 > object position x(1) + object size x(1) then object1x = object1x - 1
if object position y(2) + object size y(2) < object position y(1) + 2 then object1y = object1y + 1
if object position y(2) + 1 > object position y(1) + object size y(1) then object1y = object1y - 1
ENDIF
sync
loop
wait key
jump:
if jump = 1 then object1y=object1y+(walkspeed*2)
jump=0
return
Also, there is no doubt in my mind that my code is unnecessarily complicated. If anybody were to clean up my code or replace a few redundant commands, that would be great.
Thanx in advance:
~BlackEthereal
When life gives you lemons, make orange juice. Then sit back, drink the orange juice, and wonder how the f**k you made orange juice out of lemons.