Why isn't the collision working properly?
Here's the code:
`Camera range
set camera range 1,10000
`Collision functions
#include "collision_functions.dba"
`Load the map
load object "chicago.x",2
scale object 2,10,10,10
setupobjectdbc(2,1,0)
` Make the player
load object "h-swat-move.x",1 : ` The player
scale object 1,1000,1000,1000
yrotate object 1,180
fix object pivot 1
setupobjectdbc(1,1,0)
`load car
load object "l-taxi-move.x",3
position object 3,195,30,75
scale object 3,500,500,500
`Gravity
gravity#=0.5
`Sync
sync on
` Main Loop
DO
` Player Variables
ppX# = object position X(1) : ` The players X position
ppY# = object position Y(1) : ` The players Y position
ppZ# = object position Z(1) : ` The players Z position
paX# = object angle X(1) : ` The players X angle
paY# = object angle Y(1) : ` The players Y angle
paZ# = object angle Z(1) : ` The players Z angle
` Player movement
if upkey()=1 then playerx#=newxvalue(ppX#,paY#,1.0):playerz#=newzvalue(ppZ#,paY#,1.0)
if downkey()=1 then playerx#=newxvalue(ppX#,paY#,-1.0):playerz#=newzvalue(ppZ#,paY#,-1.0)
if leftkey()=1 then Yrotate object 1,wrapvalue(paY#-2)
if rightkey()=1 then Yrotate object 1,wrapvalue(paY#+2)
if spacekey()=1 then playery#=ppY#+1.0
`Gravity
playery#=playery#-gravity#
`Update collision info
updateobjectdbc(1)
`Test for collision
collide=intersectobjectdbc(1,1,ppX#,ppY#,ppZ#,playerx#,playery#,playerz#,0)
`Get collision coordinates and normals when collide with world
if collide>0
newx#=getStaticCollisionX()
newy#=getStaticCollisionY()
newz#=getStaticCollisionZ()
normx#=getCollisionNormalX()
normy#=getCollisionNormalY()
normz#=getCollisionNormalZ()
playerx#=newx#+normx#/10.0
playery#=newy#+normy#/10.0
playerz#=newz#+normz#/10.0
endif
`Position player
position object 1,playerx#,playery#,playerz#
` Display the player positions(to track them, part of temp. GUI)
set cursor 0,0
PRINT "Player X: ";ppX#; : ` Prints the players X position
set cursor 0,20
PRINT "Player Y: ";ppY#; : ` Prints the players Y position
set cursor 0,40
PRINT "Player Z: ";ppZ#; : ` Prints the players Z position
set cursor 0,60
print "Press spacebar to move player up"
`Camera Movement
set camera to follow ppX#,ppY#,ppZ#,paY#,25,ppY#+15,5,0
`Player animation
loop object 1
` Refresh the screen
sync
LOOP
Attatched are the media files.
J.J. Redick-Player of the year
2006 National Champions