alright, i've finished a very small libary with collision commands.
rem ************
function move_player_with_collision(objectnr,ang#,speed#,jumpr)
`the angle
objectang#=wrapvalue(ang#)
`get the old positions
yz#=object position y(objectnr)
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=newxvalue(x#,objectang#,abs(sin(objectang#))*speed#)
newz#=z#
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=x#
newz#=newzvalue(z#,objectang#,abs(cos(objectang#))*speed#)
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
`old pos
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
if jumpr=1
`if you are not jumping
if jumping(objectnr) = 0
`gravity
start_y#(objectnr) = y# - 2.0
`if you want.. and may jump
if spacekey()=1 and jumpable(objectnr) = 1
`set the variables right
jumping(objectnr) = 1
jump_angle#(objectnr) = 0
start_y#(objectnr) = object position y(objectnr)
jumpable(objectnr) = 0
endif
endif
`if you are jumping
if jumping(objectnr) = 1
`increse jump angle
jump_angle#(objectnr) = jump_angle#(objectnr) + 2
`if its 180, then stop jumping
if jump_angle#(objectnr) => 180 then jumping(objectnr)=0
endif
`position the object
position object objectnr,x#,start_y#(objectnr) + sin(jump_angle#(objectnr))*30.0,z#
`if hit..
if object collision(objectnr,coll)>0
`restore variables
jumping(objectnr) = 0
jump_angle#(objectnr) = 0
jumpable(objectnr) = 1
`reposition the object
position object objectnr,x#,yz#,z#
endif
endif
endfunction
function move_aiplayer_with_collision(objectnr,ang#,speed#,jump)
`the angle
objectang#=wrapvalue(ang#)
`get the old positions
yz#=object position y(objectnr)
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=newxvalue(x#,objectang#,abs(sin(objectang#))*speed#)
newz#=z#
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
yhit=1
endif
endif
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=x#
newz#=newzvalue(z#,objectang#,abs(cos(objectang#))*speed#)
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
yhit=1
endif
endif
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`if you are not jumping
if jumping(objectnr) = 0
`gravity
start_y#(objectnr) = y# - 2.0
`if you want.. and may jump
if yhit=1 and jump = 1 and jumpable(objectnr) = 1
`set the variables right
jumping(objectnr) = 1
jump_angle#(objectnr) = 0
start_y#(objectnr) = object position y(objectnr)
jumpable(objectnr) = 0
endif
endif
`if you are jumping
if jumping(objectnr) = 1
`increse jump angle
jump_angle#(objectnr) = jump_angle#(objectnr) + 5
`if its 180, then stop jumping
if jump_angle#(objectnr) => 180 then jumping(objectnr)=0
endif
`position the object
position object objectnr,x#,start_y#(objectnr) + sin(jump_angle#(objectnr))*40.0,z#
`if hit..
if object collision(objectnr,coll)>0
`restore variables
jumping(objectnr) = 0
jump_angle#(objectnr) = 0
jumpable(objectnr) = 1
`reposition the object
position object objectnr,x#,yz#,z#
endif
yhit=0
endfunction
function move_player_on(axis$,step#,objectnr)
objectang#=0
if axis$="x"
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=newxvalue(x#,objectang#,step#)
newz#=z#
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,0)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
if axis$="y"
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=x#
newz#=z#
newy#=y#+step#
`position the object
position object objectnr,newx#,newy#,newz#
`if hit.. restore..
if object collision(objectnr,0)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
if axis$="z"
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=x#
newz#=newzvalue(z#,objectang#,step#)
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,0)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
endfunction
function wsda_player_with_collision(objectnr,colang#)
remstart
sliding collision:
move on x
check collision
if hit.. restore x
move on z
check collision
if hit.. restore z
jump and gravity.. y
check collision
if hit.. restore y, jump = able
remend
`get the walk angle
objectang#=colang#
`get the old positions
yz#=object position y(objectnr)
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`if 'w' is pressed
if keystate(17)=1
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=newxvalue(x#,objectang#,abs(sin(objectang#)))
newz#=z#
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
`get the old positions
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`make new positions
newx#=x#
newz#=newzvalue(z#,objectang#,abs(cos(objectang#)))
newy#=y#
`position the object
position object objectnr,newx#,object position y(objectnr),newz#
`if hit.. restore..
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
endif
`the same is it with all the other directions..
if keystate(31)=1
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=newxvalue(x#,objectang#+180,1)
newz#=z#
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=x#
newz#=newzvalue(z#,objectang#+180,1)
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
endif
if keystate(32)=1
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=newxvalue(x#,objectang#+90,1)
newz#=z#
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=x#
newz#=newzvalue(z#,objectang#+90,1)
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
endif
if keystate(30)=1
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=newxvalue(x#,objectang#+270,1)
newz#=z#
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
newx#=x#
newz#=newzvalue(z#,objectang#+270,1)
newy#=y#
position object objectnr,newx#,object position y(objectnr),newz#
if object collision(objectnr,coll)>0
position object objectnr,newx#,newy#+3,newz#
if object collision(objectnr,coll)>0
`put the object back
position object objectnr,x#,y#,z#
endif
endif
endif
`old pos
x#=object position x(objectnr)
y#=object position y(objectnr)
z#=object position z(objectnr)
`if you are not jumping
if jumping(objectnr) = 0
`gravity
start_y#(objectnr) = y# - 2.0
`if you want.. and may jump
if spacekey()=1 and jumpable(objectnr) = 1
`set the variables right
jumping(objectnr) = 1
jump_angle#(objectnr) = 0
start_y#(objectnr) = object position y(objectnr)
jumpable(objectnr) = 0
endif
endif
`if you are jumping
if jumping(objectnr) = 1
`increse jump angle
jump_angle#(objectnr) = jump_angle#(objectnr) + 2
`if its 180, then stop jumping
if jump_angle#(objectnr) => 180 then jumping(objectnr)=0
endif
`position the object
position object objectnr,x#,start_y#(objectnr) + sin(jump_angle#(objectnr))*30.0,z#
`if hit..
if object collision(objectnr,coll)>0
`restore variables
jumping(objectnr) = 0
jump_angle#(objectnr) = 0
jumpable(objectnr) = 1
`reposition the object
position object objectnr,x#,yz#,z#
endif
endfunction
move_player_with_collision(objectnr,angle#,speed#,jump)
objectnr= the number of the object
ang# = the angle, the direction that the object should move
speed# = the speed
jump = if you set this to 1, you'll be automaticly able to jump with the spacebar.
move_aiplayer_with_collision(objectnr,ang#,speed#,jump)
almost the same as above, only you cant let the object jump with space, if you set jump to 1 you tell the object that it must jump if it cant get up a wall, so it automaticly jumps on it, if it cant walk on it. (sorry my english :S )
move_player_on(axis$,step#,objectnr)
axis$ = if you enter "x" it will move the object on the x axis, same for y and z
step# = howfar
objectnr = which object.
wsda_player_with_collision(objectnr,colang#)
Control an object using the wsda keys and space to jump.
colang# = the direction of the object.
Do you need a complete FPS or 3rdPS engine
?? well here it is:
http://forum.thegamecreators.com/?m=forum_view&t=38869&b=6&p=0