Hi everyone, so ive been poking around for a way to get gravity today, and i found a thread that asked very simplistically, how does one make gravity?
Well the answer to this was to use
gravity#=9.8
y#=y#-gravity#
so the person replied back and said it worked and all was dandy... the question is why is this code not working for me?
heres our code
set display mode 1280, 800, 32
Sync On
Sync Rate 100
Load Object "norse.dbo", 1
Load dll "SC_collision.dll", 1
`Load dll "DarkPhysics.dll",2
Set object transparency 1,1
Color backdrop FFFFFF
Position object 1,500,-25,500
Backdrop on
set camera range 1,10000
collision_null=memblock exist(1)
sc_setupcomplexobject 1,1,3
hide mouse
autocam off
gravity#=9.8
randomize timer()
global radius# as double float : radius# = 7.0
makePlayer()
global vtimer as integer
global view as integer : view = 1
rem make some contact markers
make object sphere 10,0.5
make object sphere 11,0.5
make object sphere 12,0.5
color object 10,rgb(255,0,0)
color object 11,rgb(0,255,0)
color object 12,rgb(0,0,255)
do
`Text 10,10,"FPS: " + str$(screen fps())
`Text 10,30,"Polygons: " + str$(statistic(1))
sync
rem hide the contact point markers
hide object 10 : hide object 11 : hide object 12
MovePlayer()
rem change view
if inkey$()="v" and vtimer<timer() then vtimer = timer()+300 : view = 1-view
positionCameraToObject(2,view)
sync
loop
function makePlayer()
make object sphere 2,radius#*2.0
`load object "warrior.x", 2
position object 2,-80,15,-20
sc_setupObject 2,0,1
set alpha mapping on 2,50
disable object zwrite 2
rem player has no group
endfunction
function movePlayer()
rem rotate player with mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
xrotate object 2,object angle x(2)+mousemovey()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
if keystate(17)=1 then move object 2,3
if keystate(31)=1 then move object 2,-3
if keystate(30)=1 then move object left 2,3
if keystate(32)=1 then move object right 2,3
x# = object position x(2)
y# = object position y(2)
z# = object position z(2)
y# = y#-gravity#
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,y#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
y# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
rem re-position the player
position object 2,x#,y#,z#
rem count the contact points and mark them
num = sc_getNumCollisions()
for i=10 to num+9
newx# = sc_getStaticCollisionX(i-9) : newy# = sc_getStaticCollisionY(i-9) : newz# = sc_getStaticCollisionZ(i-9)
normx# = sc_getCollisionNormalX(i-9) : normy# = sc_getCollisionNormalY(i-9) : normz# = sc_getCollisionNormalZ(i-9)
position object i,newx#-normx#*radius#, newy#-normy#*radius#, newz#-normz#*radius#
show object i
next i
endif
sc_updateObject 2
endfunction
function positionCameraToObject(obj,thirdPerson)
position camera object position x(2),object position y(2),object position z(2)
rotate camera object angle x(2),object angle y(2),object angle z(2)
if thirdPerson=1
pitch camera down 10
move camera -30
endif
endfunction
if anyone could shed some light as to why it wouldnt work, or offer a different solution to gravity i would love to hear it.
(also weve tried gravity with darkphysics but it gave us a fatal error crash every time we ran it)