hey guys, im doing a bit of programming again after about a year, and am making a little game. The collision is driving me nuts, which is ironic because i wrote a tutorial for basic collision a while back. Its mainly because ive forgotten much, and never really did grasp vectors when i wrote that tutorial.
Anyways, in my attempt to properly understand and apply collision, i came up with this little bit of code:
nx = object position x(1)
ny = object position y(1)
nz = object position z(1)
`Gravity
If ground = 0
ny = ny - gravity
endif
Collide = sc_sphereSlideGroup(1,ox,oy,oz,nx,ny,nz,radius,0)
If collide>0
`check the slope
Ynormal# = sc_getCollisionNormalY()
if abs(Ynormal#) > slope ` is the ceiling or ground flat?
ny = sc_getStaticCollisionY()
else ` its steep
ny = sc_getCollisionSlideY() ` eg sliding down a hill, or up a wall
endif
`slide x and z
nx = sc_getCollisionSlideX()
nz = sc_getCollisionSlidez()
`establish whether we are on the ground
if Ynormal# > 0
ground = 1`so its definitaly ground we are standing on, not a ceilling
else
ground = 0
endif
Else ` no collision
ground = 0
Endif
position object 1, nx, ny, nz
sc_updateobject 1
sc_updateobject 2
It looks fine to me, but i end up sliding all the time - but the real problem is, my box man model is not really colliding with the map- I think its the little sphere used for sphere casting. Speaking of which, when i set the radius of that sphere to more than .2, my guy just keeps flying up into the air. I have no idea.
The zip file of the whole project so far is attached
Thanks for the help
Aralox