hi guys im new to darkbasic pro and this is my first post.
im trying to make a ball hang from a movible stick with pyshics
nothing fancy, but i'm bit stuck on how to make it work.
i've included my code,the whole thing maybe wrong but at least you will get a idea of what im trying to do(and hopefully show me how to do it). thanks!
sync on ; null=make vector3(1)
make object cube 1,0.1
position object 1,0,0,0
make object cube 2,0.05
position object 2,0,0,0
global ball_speed#
global string_length#=1.0
global gravity#=0.02
global friction#=0.0002
do
dist#=getdist(object position x(1),object position y(1),object position z(1),object position x(2),object position y(2),object position z(2),)
position object 2,object position x(2),object position y(2)-gravity#,object position z(2)
if dist#>string_length#
ball_speed#=dist#-string_length#
point object 2,object position x(1),object position y(1),object position z(1)
move object 2,ball_speed#
endif
speed#=0.01
if upkey() then position object 1,object position x(1),object position y(1),object position z(1)+speed#
if downkey() then position object 1,object position x(1),object position y(1),object position z(1)-speed#
if leftkey() then position object 1,object position x(1)-speed#,object position y(1),object position z(1)
if rightkey() then position object 1,object position x(1)+speed#,object position y(1),object position z(1)
move object 2,ball_speed#
sync ; loop
function getdist(x1#,y1#,z1#,x2#,y2#,z2#)
set vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
distance#=length vector3(1)
endfunction distance#