Ok, ive been looking over all this code I have. I've organized it a bit, ive tried other codes with it, ive adjusted it in many ways. I always get the same outcome,
I dont know what to do anymore!
its like my collision wont work with this code either. But I really like the controls in that code. I dont think im experienced enough to know whats wrong with this.
sync rate 20 : sync on
MAKE MATRIX 1,1000,1000,10,10
POSITION MATRIX 1,-500,0,-500
`Make the user's object.
MAKE OBJECT CUBE 1,20
POSITION OBJECT 1,0,5,0
`Make a box object, replace this with your map.
MAKE OBJECT BOX 2,100,50,50
GHOST OBJECT ON 2
POSITION OBJECT 2,0,25,60
`Setup object 2, the map, to be in group 0, and to be set to collision
`type 0 - "Polygon".
SC_SetupObject 2,0,0
getcharcol = 0
do
`Store the user's old position on the xyz axis
OX# = OBJECT POSITION X(1)
OY# = OBJECT POSITION Y(1)
OZ# = OBJECT POSITION Z(1)
Action()
`Store the player's new position on the xyz axis, after they've moved.
X# = OBJECT POSITION X(1)
Y# = OBJECT POSITION Y(1)
Z# = OBJECT POSITION Z(1)
`Call the sliding collision function, filling in the necassary variables
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,2)
print getcharcol
sync
loop
`Sliding Collision Function
FUNCTION SlidingCollision(X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,Dyn,Obj)
`X1#-Z1# : The starting XYZ position of the intersection ray
`X2#-Z2# : The ending XYZ position of the intersection ray
`Radius# : The radius of the sliding collision sphere, usually you'd set this
` to the player's object's z sixe divided by 2. Our cube is 20 units thick,
` so we use 10 in the example.
`Dyn : The player object
`Obj : The map object that we want the player object to slide on
`Call the sc_SphereSlide command, using our variables.
`This command will create a mathematical intersection "Ray",
`this basically means that it'll make a 3D line starting from X1#,Y1#,Z1#,
`and ending at X2#,Y2#,Z2#. It'll then check if any of the polygons on the
`map object are inbetween these 2 points, if there is then it'll return a 1,
`if not, it'll return 0.
`What Sparky has done for us however is added in a few handy functions
`that are carried out inside of the SphereSlide command. Basically,
`once it detects an intersection, it'll get the angle the intersection
`occured at and using trigonometry (sin, cos and tan), it'll determine
`the logical position for an object to be if it were to "slide" along
`the polygon it hit. To make the system even more accurate however,
`Sparky's dll goes one step further by doing another intersection check on the
`new mathematical coordinates it just obtained, and checks that there wont be
`a collision there either. `It'll keep doing this until it reaches it's max
`iteration or until it finds a free, empty 3d location where the player's object
`can go. All this for free, sheesh!
C = sc_SphereSlide(Obj,X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,0)
`Now, sparky's dll will return the 3d position it thinks you should position your
`player object at AS WELL. These positions are returned using the sc_getCollisionSlideXYZ()
`commands. Basicaly the next code checks if an intersection occured in the first place
` (if C > 0), and if one did, then it retrieves the new XYZ location that the player should be
`placed at, and then positions the player object there accordingly.
IF C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
POSITION OBJECT Dyn, cx#, cy#, cz#
ENDIF
ENDFUNCTION
`This last bit is a requirement of Sparky's dll. Basically, DBP's commands are grouped into plugins themselves.
`Theres a plugin for Camera commands, a plugin for Object commands, a plugin for Network commands, etc.
`However DBP, at the time of writing, includes only the necassary plugins for the program to work. So if you dont use
`and 3D commands, it wont include any 3D plugins. Sparky's dll requires the memblock commands, we haven't used any
`memblock commands yet so DBP wont include the Memblock plugin, which means Sparky's dll will crash. To fix this, we
`just add a DELETE MEMBLOCK 1 command after the function. DBP will never read this code, and so it will never get
`executed, but it will make DBP include the Memblock plugin.
FUNCTION Action()
`//Keyboard//
if upkey() or downkey() or leftkey() or rightkey()
rem Get the angle of the keys, and add the camera angle.
targetangle#=atanfull(rightkey()-leftkey(),upkey()-downkey())+camangle#
rem This angle is then smoothed to prevent jerkiness. 5 is how many frames turning should take.
angle#=curveangle(targetangle#,angle#,10)
rem Apply the angle to the character.
yrotate object 2,angle# `//*use when changing player model*//
`//Run and Sneak//
if Keystate(30)
speed#=curvevalue(4,speed#,15)
else
if Keystate(31)
speed#=curvevalue(.5,speed#,5)
endif
if keystate(30)=0 and keystate(31)=0 then
rem Smooth acceleration. 0.2 is the speed, 5 is how long it should take.
speed#=curvevalue(1,speed#,30)
endif
`/////
rem Turn the camera if the player is going left or right.
inc targetcamangle#,sin(targetangle#-camangle#)
if leftkey()
inc targetcamangle#,-2
else
if rightkey()
inc targetcamangle#,2
endif
endif
rem Is down being pressed?
if downkey()
rem Was it being pressed last frame?
if antirep=0
rem If only downkey is being pressed, do a 180 spin.
if leftkey()=0 and rightkey()=0 and upkey()=0
inc targetcamangle#,180
endif
rem Prevent repeat spins.
antirep=1
endif
else
rem if the downkey isn't being pressed, reset antirep.
antirep=0
endif
else
` rem If the player's not moving, do gentle slowdown. 5 is how many frames it takes to stop.
speed#=curvevalue(0.0,speed#,20)
endif
`rem Smooth the camera. No jerkiness.
camangle#=curvevalue(targetcamangle#,camangle#,15)
`Rem This is essentially move object. *Use when changing Player model*
position object 2,object position x(2)+(sin(angle#)*speed#),0,object position z(2)+(cos(angle#)*speed#)
`Rem positioning the camera behind the player. the *'s are distance from character ,#,is the height 2 is the object
position camera object position x(2)-(sin(camangle#)*15),5,object position z(2)-(cos(camangle#)*20)
`Rem Point the camera above the player's head. *Use when changing player model*
point camera object position x(2),1,object position z(2)
ENDFUNCTION
`If you've used a memblock command elsewhere in your project, then y
DELETE MEMBLOCK 1
then try this
sync rate 20 : sync on
MAKE MATRIX 1,1000,1000,10,10
POSITION MATRIX 1,-500,0,-500
`Make the user's object.
MAKE OBJECT CUBE 1,20
POSITION OBJECT 1,0,5,0
`Make a box object, replace this with your map.
MAKE OBJECT BOX 2,100,50,50
GHOST OBJECT ON 2
POSITION OBJECT 2,0,25,60
`Setup object 2, the map, to be in group 0, and to be set to collision
`type 0 - "Polygon".
SC_SetupObject 2,0,0
getcharcol = 0
do
`Store the user's old position on the xyz axis
OX# = OBJECT POSITION X(1)
OY# = OBJECT POSITION Y(1)
OZ# = OBJECT POSITION Z(1)
MOVE OBJECT 1,( UPKEY()-DOWNKEY() ) * .5
TURN OBJECT LEFT 1,( LEFTKEY()-RIGHTKEY() ) * .5
`Store the player's new position on the xyz axis, after they've moved.
X# = OBJECT POSITION X(1)
Y# = OBJECT POSITION Y(1)
Z# = OBJECT POSITION Z(1)
`Call the sliding collision function, filling in the necassary variables
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,2)
`//Keyboard//
if upkey() or downkey() or leftkey() or rightkey()
rem Get the angle of the keys, and add the camera angle.
targetangle#=atanfull(rightkey()-leftkey(),upkey()-downkey())+camangle#
rem This angle is then smoothed to prevent jerkiness. 5 is how many frames turning should take.
angle#=curveangle(targetangle#,angle#,10)
rem Apply the angle to the character.
yrotate object 2,angle# `//*use when changing player model*//
`//Run and Sneak//
if Keystate(30)
speed#=curvevalue(4,speed#,15)
else
if Keystate(31)
speed#=curvevalue(.5,speed#,5)
endif
if keystate(30)=0 and keystate(31)=0 then
rem Smooth acceleration. 0.2 is the speed, 5 is how long it should take.
speed#=curvevalue(1,speed#,30)
endif
`/////
rem Turn the camera if the player is going left or right.
inc targetcamangle#,sin(targetangle#-camangle#)
if leftkey()
inc targetcamangle#,-2
else
if rightkey()
inc targetcamangle#,2
endif
endif
rem Is down being pressed?
if downkey()
rem Was it being pressed last frame?
if antirep=0
rem If only downkey is being pressed, do a 180 spin.
if leftkey()=0 and rightkey()=0 and upkey()=0
inc targetcamangle#,180
endif
rem Prevent repeat spins.
antirep=1
endif
else
rem if the downkey isn't being pressed, reset antirep.
antirep=0
endif
else
` rem If the player's not moving, do gentle slowdown. 5 is how many frames it takes to stop.
speed#=curvevalue(0.0,speed#,20)
endif
`rem Smooth the camera. No jerkiness.
camangle#=curvevalue(targetcamangle#,camangle#,15)
`Rem This is essentially move object. *Use when changing Player model*
position object 2,object position x(2)+(sin(angle#)*speed#),0,object position z(2)+(cos(angle#)*speed#)
`Rem positioning the camera behind the player. the *'s are distance from character ,#,is the height 2 is the object
position camera object position x(2)-(sin(camangle#)*15),5,object position z(2)-(cos(camangle#)*20)
`Rem Point the camera above the player's head. *Use when changing player model*
point camera object position x(2),1,object position z(2)
print getcharcol
sync
loop
`Sliding Collision Function
FUNCTION SlidingCollision(X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,Dyn,Obj)
`X1#-Z1# : The starting XYZ position of the intersection ray
`X2#-Z2# : The ending XYZ position of the intersection ray
`Radius# : The radius of the sliding collision sphere, usually you'd set this
` to the player's object's z sixe divided by 2. Our cube is 20 units thick,
` so we use 10 in the example.
`Dyn : The player object
`Obj : The map object that we want the player object to slide on
`Call the sc_SphereSlide command, using our variables.
`This command will create a mathematical intersection "Ray",
`this basically means that it'll make a 3D line starting from X1#,Y1#,Z1#,
`and ending at X2#,Y2#,Z2#. It'll then check if any of the polygons on the
`map object are inbetween these 2 points, if there is then it'll return a 1,
`if not, it'll return 0.
`What Sparky has done for us however is added in a few handy functions
`that are carried out inside of the SphereSlide command. Basically,
`once it detects an intersection, it'll get the angle the intersection
`occured at and using trigonometry (sin, cos and tan), it'll determine
`the logical position for an object to be if it were to "slide" along
`the polygon it hit. To make the system even more accurate however,
`Sparky's dll goes one step further by doing another intersection check on the
`new mathematical coordinates it just obtained, and checks that there wont be
`a collision there either. `It'll keep doing this until it reaches it's max
`iteration or until it finds a free, empty 3d location where the player's object
`can go. All this for free, sheesh!
C = sc_SphereSlide(Obj,X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,0)
`Now, sparky's dll will return the 3d position it thinks you should position your
`player object at AS WELL. These positions are returned using the sc_getCollisionSlideXYZ()
`commands. Basicaly the next code checks if an intersection occured in the first place
` (if C > 0), and if one did, then it retrieves the new XYZ location that the player should be
`placed at, and then positions the player object there accordingly.
IF C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
POSITION OBJECT Dyn, cx#, cy#, cz#
ENDIF
ENDFUNCTION
`This last bit is a requirement of Sparky's dll. Basically, DBP's commands are grouped into plugins themselves.
`Theres a plugin for Camera commands, a plugin for Object commands, a plugin for Network commands, etc.
`However DBP, at the time of writing, includes only the necassary plugins for the program to work. So if you dont use
`and 3D commands, it wont include any 3D plugins. Sparky's dll requires the memblock commands, we haven't used any
`memblock commands yet so DBP wont include the Memblock plugin, which means Sparky's dll will crash. To fix this, we
`just add a DELETE MEMBLOCK 1 command after the function. DBP will never read this code, and so it will never get
`executed, but it will make DBP include the Memblock plugin.
delete memblock 1
Do you see any difference?
please any help would be nice