Okay, new problem.
I tried to implement sliding collision. Is there something wrong with my sliding collision function? Here is my full source:
sync on
sync rate 60
rem Define Types
type character
objectid
name$
age
speed#
endtype
type friendly
istaken
objectid
name$
age
speed#
x#
y#
z#
doesplayerknow
endtype
rem Define Variables
global NO = 0
global YES = 1
global TRUE = YES
global FALSE = NO
global CHAR = 1
global MOVESPEED# = 0.1
global CHARX#
global CHARY#
global CHARZ#
global SCREENMIDX = 512
global SCREENMIDY = 384
global player as character
player.objectid = CHAR
player.speed# = MOVESPEED#
global dim npc(5000) as friendly
global OLDCHARX#
global OLDCHARY#
global OLDCHARZ#
rem Other Pre-Loop Setup
hide mouse
CreateMainCharacter()
UpdateCharacterPosition()
CreateNPC(0, 0, 5, "Arborum", 34, MOVESPEED#, 100, 0)
rem GAME LOOP
rem *************************************************************************************
rem *************************************************************************************
do
rem Update Early Variables
UpdateOldCharacterPosition()
rem Check for Input
GetKeyInput()
GetMouseInput()
rem DoCollisionChecks
NPCSlidingCollision()
rem Collision Checks
rem NPCSlidingCollision()
rem Position the Camera
PositionCamera()
rem Update Late Variables
UpdateCharacterPosition()
rem Display the HUD
DisplayHUD()
rem Sync
sync
loop
rem FUNCTIONS
rem *************************************************************************************
rem *************************************************************************************
function CreateMainCharacter()
make object sphere CHAR, 1
endfunction
function GetKeyInput()
if keystate(17) = 1
MoveCharacterUp(player.speed#)
endif
if keystate(30) = 1
MoveCharacterLeft(player.speed#)
endif
if keystate(31) = 1
MoveCharacterBack(player.speed#)
endif
if keystate(32) = 1
MoveCharacterRight(player.speed#)
endif
endfunction
function GetMouseInput()
endfunction
function MoveCharacterUp(velocity#)
move object CHAR, velocity#
endfunction
function MoveCharacterLeft(velocity#)
move object left CHAR, velocity#
endfunction
function MoveCharacterRight(velocity#)
move object right CHAR, velocity#
endfunction
function MoveCharacterBack(velocity#)
move object CHAR, -velocity#
endfunction
function PositionCamera()
position camera CHARX#, CHARY#, CHARZ#
rotate camera camera angle x(0)+(mousemovey()*0.1),camera angle y(0)+(mousemovex()*0.1),0
rotate object CHAR, camera angle x(0),camera angle y(0),0
DrawCrosshair()
endfunction
function UpdateCharacterPosition()
CHARX# = object position x(CHAR)
CHARY# = object position y(CHAR)
CHARZ# = object position z(CHAR)
endfunction
function UpdateOldCharacterPosition()
OLDCHARX# = object position x(CHAR)
OLDCHARY# = object position y(CHAR)
OLDCHARZ# = object position z(CHAR)
endfunction
function DrawCrosshair()
circle screen width()/2, screen height()/2, 5
endfunction
function CreateNPC(x#, y#, z#, name$, age, speed#, objectid, npcid)
if npc(npcid).istaken = FALSE
npc(npcid).istaken = TRUE
npc(npcid).x# = x#
npc(npcid).y# = y#
npc(npcid).z# = z#
npc(npcid).name$ = name$
npc(npcid).age = age
npc(npcid).speed# = speed#
npc(npcid).objectid = objectid
make object sphere objectid, 1
position object objectid, x#, y#, z#
sc_setupobject objectid, 0, 0
else
exitfunction
endif
endfunction
function DisplayHUD()
text 5, 5, "FPS: " + str$(screen fps())
text 5, 20, "x: " + str$(CHARX#)
text 5, 35, "y: " + str$(CHARY#)
text 5, 50, "z: " + str$(CHARZ#)
endfunction
function SlidingCollision(x1#, y1#, z1#, x2#, y2#, z2#, radius#, dyn, obj)
c = sc_sphereslide(obj, x1#, y1#, z1#, x2#, y2#, z2#, radius#, 0)
if c > 0
cx# = sc_getcollisionslidex()
cy# = sc_getcollisionslidey()
cz# = sc_getcollisionslidez()
position object dyn, cx#, cy#, cz#
endif
endfunction
function NPCSlidingCollision()
for x = 0 to 5000
SlidingCollision(OLDCHARX#, OLDCHARY#, OLDCHARZ#, CHARX#, CHARY#, CHARZ#, 0.5, 1, npc(x).objectid)
next
endfunction
delete memblock 1
All help will be appreciated.