Hi, I've been working on my mmorpg-ish game Blades of War (SOEGW) and I have ran into a problem. I can't seem to work out how to use sparky collision for the world map which is made by Blitz terrain.
This is the world map being made and setup
//Load media
global g_HeightmapImgID : global g_TextureImgID : global g_DetailmapImgID : global g_EnvironmentmapImgID
g_HeightmapImgID=1996 : g_TextureImgID=1997 : g_DetailmapImgID=1998 : g_EnvironmentmapImgID=1999
load image "World/Ashguard/AshguardHeightmap.bmp",g_HeightmapImgID
load image "World/Ashguard/AshguardTexture.jpg",g_TextureImgID
load image "World/Ashguard/AshguardDetail.tga",g_DetailmapImgID
load image "World/Ashguard/AshguardEnvironment.bmp",g_EnvironmentmapImgID
//Create terrain
//Make the terrain
g_TerrainID=1
global g_TerrainID
g_TerrainID=BT MakeTerrain()
//Set images
BT SetTerrainHeightmap g_TerrainID,g_HeightmapImgID
BT SetTerrainTexture g_TerrainID,g_TextureImgID
BT SetTerrainDetail g_TerrainID,g_DetailmapImgID
BT SetTerrainEnvironment g_TerrainID,g_EnvironmentmapImgID
//Set some other values
BT SetTerrainScale g_TerrainID,120.0
BT SetTerrainYScale g_TerrainID,30.0
BT SetTerrainSplit g_TerrainID,32
BT SetTerrainDetailTile g_TerrainID,3.0
//LOD
BT SetTerrainLOD g_TerrainID,3 //3 LOD levels
BT SetTerrainLODDistance g_TerrainID,1,100.0 //LOD Distances start at one and go up to 1 less the LOD level count
BT SetTerrainLODDistance g_TerrainID,2,200.0
//Smoothing and Quad Rotation
BT SetTerrainSmoothing g_TerrainID,3
BT SetTerrainQuadRotation g_TerrainID,1
//Environment maps
EM_Empire=BT AddTerrainEnvironment(g_TerrainID,rgb(255,106,0)) //Seccond parameter tells the system which colour represents this environment on the environment map
EM_HighLords=BT AddTerrainEnvironment(g_TerrainID,rgb(225,0,0))
EM_Sea=BT AddTerrainEnvironment(g_TerrainID,rgb(96,38,0))
//Build
global g_TerrainObjectID
g_TerrainObjectID=40
//This command processes the heightmap and creates all the internal structures for the terrain
BT BuildTerrain g_TerrainID,g_TerrainObjectID,1
SC_setupTerrainCollision g_TerrainObjectID,1,g_TerrainObjectID+1
This function is called every loop for the movement (needs to be improved as it is the basic code which is shown in a example)
Rem ============== Keyboard ===============
oldx# = object position x(PlayerObj)
oldy# = object position y(PlayerObj)
oldz# = object position z(PlayerObj)
rem apply gravity, and user changes to movement
angy# = object angle y(PlayerObj)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#) * 2 : vz# = vz# - sin(angy#) * 2
if keystate(30)=1 then vx# = vx# - cos(angy#) * 2 : vz# = vz# + sin(angy#) * 2
if keystate(31)=1 then vx# = vx# - sin(angy#) * 2 : vz# = vz# - cos(angy#) * 2
if keystate(17)=1 then vx# = vx# + sin(angy#) * 2 : vz# = vz# + cos(angy#) * 2
rem only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
rem handle gravity - seperated from horizontal movement
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object PlayerObj,x#,oldy#,z#
sc_updateObject PlayerObj
sc_updateObject g_TerrainObjectID
Thanks for any help!