Hi all,
I've made a small libary with collision commands.
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.
Here is the libary:
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
Here an example code, how to use:
sync on
sync rate 75
autocam off
rem enable the collision
prepare_collision(300)
sync
center text 320,240,"Example for the use of this libary"
sync
wait key
20:
cls
text 30,10,"1. First person shooter example"
text 30,30,"2. Third person shooter example"
set cursor 30,70
input "what is your choice? ";ch
rem fog
fog on
fog distance 100
set ambient light 0
rem make player
make object cube 1,15
position object 1,0,40,0
xrotate object 1,45
zrotate object 1,45
rem make a level
make object box 10,1000,10,1000
position object 10,0,-10,0
make object cube 11,30
place_object(0,0,100,11)
make object cube 12,40
place_object(30,0,80,12)
make object box 20,20,5,5
place_object(-30,0,20,20)
make object box 21,20,5,5
place_object(-30,5,25,21)
make object box 22,20,5,5
place_object(-30,10,30,22)
make object box 23,20,5,5
place_object(-30,15,35,23)
make object box 24,20,5,78
place_object(-30,25,75,24)
xrotate object 24,-10
rem enable the collision
rem 0 for all, other number for specified object
put_collision_on(0)
if ch=1 then goto first
if ch=2 then goto third
first:
do
sync
set cursor 0,0
print "First person shooter example by jopie dopie"
yang#=yang#+mousemovex()
xang#=xang#+mousemovey()
wsda_player_with_collision(1,yang#)
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
position camera x#,y#,z#
rotate camera xang#,yang#,0
loop
third:
hide object 1
make object sphere 2,20
set object collision off 2
do
sync
set cursor 0,0
print "Third person shooter example by jopie dopie"
yang#=yang#+mousemovex()*0.3
xang#=xang#+mousemovey()*0.3
if xang# < -15 then xang#= -15
if xang# > 40 then xang# = 40
wsda_player_with_collision(1,yang#)
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
position object 2,x#,y#,z#
yrotate object 2,yang#
set camera to follow x#,y#,z#,yang#,30,20+xang#,10,10
point camera x#,y#,z#
loop
function place_object(x#,y#,z#,o)
position object o,x#,y#+(object size y(o)/2),z#
endfunction
rem ************ libary
function put_collision_on(number)
if number = 0
for object = 1 to 1000000
if object exist(object)=1
set object collision on object
endif
next object
else
set object collision on number
endif
endfunction
function prepare_collision(amount)
dim jumping(amount)
dim start_y#(amount)
dim jump_angle#(amount)
dim jumpable(amount)
endfunction
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) + 4
`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))*20.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
If you want to read more about it, my old thread:
http://forum.thegamecreators.com/?m=forum_view&t=38869&b=6
cheers
Do you need a complete FPS,3rdPS engine
?? Or a collision command libary?? well here it is:
http://forum.thegamecreators.com/?m=forum_view&t=38869&b=6&p=0