OK im working an my game,BUT i never learned collision
AND i cant figure it out either...
so i decided to ask for help.Ill post my code and Hopefully that helps enough to get it working at your place(It uses DB Collision DLL V2.0)
Long code:
`Variables ---------------------------------------
global YANGLE# as float
global PACKETS_SENT as integer
global PACKETS_RECEIVED as integer
global connected as boolean
global newPlayer as integer
global stateP1 as boolean
global playerMade as boolean
matnum=1
gridamount=100
tilesize=10000
`-------------------------------------------------
`Ask for local IP
input "IP: ",IP$
`Act as server
connected = net host(20,IP$)
net stack on
`If hosting failed, tell the user then exit
if connected=0
print "FAILED"
wait 2000
end
endif
` Turn sync on
sync on
sync rate 60
`Make player
make object cube 1,10
color object 1,rgb(255,0,0)
sc_setupObject 1,0,1
`Make the world
make matrix 1,10,10,1,1
position matrix 1,30000,-1000,2000
load object "Media\Mesh.x",3
sc_setupComplexObject 3,1,2
`sc_setupObject 1,1,0
position object 3,-2000,-50,-2000
do
`Display number of packets sent and received
text 0,0,"Packets sent: "+str$(PACKETS_SENT)
text 0,13,"Packets PACKETS_RECEIVED: "+str$(PACKETS_RECEIVED)
`Display fps
text 0,26,"Screen fps: "+str$(screen fps())
`Display packets per second received
packs = net get packetspersecond()
text 0,39,"Packets per second: "+str$(packs)
stateP1 = net get player state(1)
text 0,100,"Player 1 exists?: "+str$(stateP1)
`Make a little delay then send coordinates
inc sendDelay
if sendDelay = 5 then SendCoordinates() : sendDelay=0
`Check player
Player()
`Reveive coordinates
StackRecv()
`Handle controls
Controls()
`Handle camera
Camera()
`Update the screen
sync
loop
FUNCTION Player()
newPlayer = net new player()
`If there is a new player, make its object
if newPlayer = 1 and object exist(2)=0
make object cube 2,10
color object 2,rgb(0,255,0)
playerMade = 1
endif
stateP1 = net get player state(1)
if object exist(2)
if stateP1=0 then hide object 2 else show object 2
endif
ENDFUNCTION
FUNCTION SendCoordinates()
state = net get player state(1)
`Send the host coordinates to all players
if state
x# = object position x(1)
z# = object position z(1)
angle# = YANGLE#
net push float x#
net push float z#
net push float angle#
net send 1
inc PACKETS_SENT
endif
ENDFUNCTION
FUNCTION StackRecv()
if net receive(1)
inc PACKETS_RECEIVED
msgAmount = net get msg amount()
for x=1 to msgAmount
net get msg
angle# = net pop float()
z# = net pop float()
x# = net pop float()
position object 2,x#,0,z#
yrotate object 2,angle#
inc PACKETS_RECEIVED
next x
endif
ENDFUNCTION
FUNCTION Camera()
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(1)+180)
`grab the objects current position
xPos#=object position x(1)
yPos#=object position y(1)
zPos#=object position z(1)
`other variables
camDist=30
camHeight=10
`work out new position
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newzvalue(zPos#,yAng#,camDist)
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos# < yPos#+camHeight then yCamPos#=yPos#+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight,zPos#
endfunction
function memblock()
make memblock 1,1
if memblock exist(1)
Print "IT WORKS!"
endif
endfunction
function Controls()
rem rotate player with mouse
yrotate object 1,object angle y(1)+mousemovex()/3.0
oldx# = object position x(1)
oldy# = object position y(1)
oldz# = object position z(1)
angy# = object angle y(1)
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#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
oldy# = sc_getStaticCollisionY()
else
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
if ny#>slope#
ground = 1
vy# = 0
else
ground = 0
if ny#<-slope# then vy# = gravity#
endif
else
oldy# = oldy# + vy#
ground = 0
endif
if ground = 1 and jumptimer>0 then dec jumptimer
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
endif
position object 1,x#,oldy#,z#
sc_updateObject 1
endfunction