younis12,
One thing missed was 'Sc_Allowobjectscaling' for object 5. You then would need to move the 'scale object' command after this, followed by 'Sc_UpdateObject'.
I have made several adjustments to the program that helpfully illustrates the gravity effect you are looking for. The adjustments are documented. I just have the floor loaded into Sparky collision. I would suggest loading all of your objects into it rather than mixing between DBPro native and Sparky Collision.
sync on
sync rate 60
set camera range 1,1000000
rem health p1
box 0,0,health,15
ink rgb(0,255,0),rgb(0,255,0)
randomize timer()
global radius# as double float : radius# = 6.0
makeLevel()
makePlayer()
global vtimer as integer
global view as integer : view = 1
health = 150
do
`*** changed print to text
Ink 0,0
Text 0, Screen Height()-20,str$( Object Position Y(2) ) `*** position text at bottom of screen
ink rgb(255,0,0),rgb(255,0,0)
box 0,0,150,15
ink rgb(0,255,0),rgb(0,255,0)
box 0,0,health,15
if health > 150 then health = 150
if health > 0
if object collision(2,6)>0 then dec health,2
Endif
If health > 0
if object collision (2,3)>0 then inc health,2
endif
applyGravity(3) `*** show Box dropping
MovePlayer()
positionCameraToObject(2,view)
sync
loop
function makeLevel()
rem health -
make object sphere 6,200
Position Object 6,500,0,500
Set Object Collision To Spheres 6
rem health +
make object cube 3,50
// Position Object 3,250,200,250
Position Object 3,150,200,250 `*** moved Box location so you can see it drop better
Set Object Collision To Boxes 3
Make Object Cube 5,50
position object 5,0,-5,0
Set Object Collision To Boxes 5
Sc_Setupcomplexobject 5,1,2
Sc_Allowobjectscaling 5 `*** turned this on
Scale Object 5,10000,10,10000 `*** moved from above
Sc_Updateobject 5 `*** update the scaled florr
Endfunction
function makePlayer()
Make Object Sphere 2,radius#*2.0
Position Object 2,0,100,0
// Sc_Setupobject 2,0,1 `*** removed because it is currently not used / needed
endfunction
function movePlayer()
ay# = Object Angle Y(2)
// oldx# = object position x(2)
// oldy# = object position y(2)
// oldz# = object position z(2)
if upkey()=1 then move object 2,10
If Downkey()=1 Then Move Object 2,-10
if rightkey()=1 then yrotate object 2,wrapvalue(ay#+3)
If Leftkey()=1 Then Yrotate Object 2,wrapvalue(ay#-3)
// x# = object position x(2)
// y# = object position y(2)
// z# = object position z(2)
//
// collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,y#,z#,radius#,0)
//
// if collide>0
// x# = sc_getCollisionSlideX()
// y# = sc_getCollisionSlideY()
// z# = sc_getCollisionSlideZ()
//
// position object 2,x#,y#,z#
//
// endif
applyGravity(2) `*** apply gravity To player
endfunction
Function applyGravity(thisObject)
`*** very simple gravity example
gs = 5
theight# = Terrain_Height(x#, z#, thisObject)
x# = Object Position x(thisObject)
y# = Object Position Y(thisObject) - (Object Size Y(thisObject) / 2) `*** get the bottom of the object, assuming that 'Y' is the center of the object
z# = Object Position Z(thisObject)
If y# > theight#
Move Object Down thisObject , gs
Endif
If y# < theight#
Position Object thisObject, x#, theight# + (Object Size Y(thisObject) / 2), z#
Endif
Endfunction
function positionCameraToObject(obj,thirdPerson)
// Hodgey's edit
angle = Object Angle Y(obj)
//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)
distance as float = 30.0
// rotate the object
// if rightkey()=1 then angle = wrapvalue(angle + 1.0) `*** removed as it is in movePlayer()
// if leftkey()=1 then angle = wrapvalue(angle - 1.0)
// Yrotate Object obj, angle
// poisition the camera according the the player's coordinates and rotation
camx = (-sin(angle)*distance)+object position x(obj)
camy = Object Position Y(obj) + (Object Size Y(obj) / 2)
camz = (-cos(angle)*distance)+object position z(obj)
position camera camx, camy, camz
// point the camera towards the player
point camera object position x(2), object position y(2), object position z(2)
endfunction
Function Terrain_Height(posX#, posZ#, obj)
// If Sc_Raycastgroup(1,posX#,10000,posZ#,posX#,-10000,posZ#, obj) > 0
If Sc_Raycast(5,posX#,10000,posZ#,posX#,-10000,posZ#, obj) > 0
terrHeight# = Sc_Getstaticcollisiony()
Endif
Endfunction terrHeight#
If Memblock Exist(1) Then Delete Memblock 1
Regards,