First off this is my first post, I\'m pretty much a noob if thats what you wanna call me lol, but I thought to just post a little snippet of something I was kinda working on. I\'m sure I may end up developing this more but it\'s a major learning process for me. So here\'s the deal, basically this snippet shows sliding collision with a simple little scene i built out of box objects bounded by collision boxes and a cylinder object which is controlled via the mouse. I found cylinder objects give the best appearance for collision in this situation. Using boxes or cubes didnt seem to look right as certain parts of the cubes would go a little into the walls when colliding, primarily the corners of the box that you control. I know the controls may be a little awkward as the cam is pretty stationary and you spin the object around on it\'s y axis to rotate it with the mouse. The cam just pretty well follows its direction with the point camera command but dont actually follow it around. No biggie though, prolly something I\'ll just work in later. Oh, by the way, the left mouse button also jumps the cylinder object so you can jump up on the platform. So my apologies if tis a basic stupid code but it may go further and be something more and I can remark it better as I learn more. I know its nothing to go oooh and ahhh over, but just a little something to give .So anyhow, enough of my babble, here\'s the code.
`Jumping code for 3D with sliding collision
`real simple one key jump control
`quick program setups
set display mode 800,600,32
set window on : set window size 800,600 : maximize window
sync on : sync rate 75 : autocam on
hide mouse
backdrop on : color backdrop rgb(5,5,5)
`global
CylinderGravity# = 3.0
True# = 1 : False# = 0
MouseSpeed# = 0.3
`position the camera to view the scene
position camera 0,25,-50 : xrotate camera 15
`setup a basic scene to look at
make object box 1,100,10,100 : `floor
color object 1,rgb(100,100,100)
make object collision box 1,-50,-5,-50,50,5,50,0 : `collision box for floor
position object 1,0,0,0
make object cylinder 2,10 : `our test object for gravity
color object 2,rgb(125,0,0)
make object collision box 2,-5,-5,-5,5,5,5,0 : `collision box for gravity object
position object 2,0,15,0
`make object box 2,10,10,10
`color object 2,rgb(50,0,0)
`make object collision box 2,-7.5,-7.5,-7.5,7.5,7.5,7.5,0
`position object 2,0,15,0
make object box 3,100,10,100 : `some steps to go up
color object 3,rgb(100,100,100)
make object collision box 3,-50,-5,-50,50,5,50,0
position object 3,0,10,100
make object box 4,10,10,100
color object 4,rgb(100,100,100)
make object collision box 4,-5,-5,-50,5,5,50,0
position object 4,-50,10,0
make object box 5,10,10,100
color object 5,rgb(100,100,100)
make object collision box 5,-5,-5,-50,5,5,50,0
position object 5,50,10,0
make object box 6,100,10,10
color object 6,rgb(100,100,100)
make object collision box 6,-50,-5,-5,50,5,5,0
position object 6,0,10,-50
`main program loop
do
`mouselook code for turning the cylinder object
`this mouse look code is designed to provide a smooth swing to the mouse rather than choppy
oldcamangleY#=camera angle y()
camangley# = wrapvalue(camangley#+MouseMoveX()*MouseSpeed#)
yrotate camera curveangle(camangley#,oldcamangley#,15)
`rotate the cylinder object based on mouse input
yrotate object 2, curveangle(camangleY#, oldcamangleY#, 1)
`store cylinder objects old x,y, and z coordinates for static collision
CylinderOldX# = object position x(2)
CylinderOldY# = object position y(2)
CylinderOldZ# = object position z(2)
`check if jumping condition exists via key press
if mouseclick() = True# and CylinderGravity# = 0.0
CylinderGravity# = 3.0
endif
if upkey() = 1
move object 2, 0.5
endif
if downkey()=1
move object 2, -0.5
endif
`record objects current position on x,y,z
CylinderPositionX# = object position x(2)
CylinderPositionY# = object position y(2)
CylinderPositionZ# = object position z(2)
`initialise gravity force
CylinderGravity# = CylinderGravity# - 0.11/1.0
CylinderPositionY# = CylinderPositionY# + CylinderGravity#
`check to see if cylinder is touching with floor object
`this section repositions the object according to the input, then checks for collision
position object 2, CylinderPositionX#, CylinderPositionY#, CylinderPositionZ#
if object collision(2,0)>0
dec CylinderPositionX#, get object collision x()
dec CylinderPositionY#, get object collision y()
dec CylinderPositionZ#, get object collision z()
CylinderGravity# = 0.0
endif
`update new position
`running this again to position the cylinder object based on if collision exists on the y() axis
`removing this line will cause the cylinder to collide with platforms but gradually sink through them until no collision detected
`then drop off immediately
position object 2, CylinderPositionX#, CylinderPositionY#, CylinderPositionZ#
`track the objects movements with the camera
`simply put this basically just points the camera at the object wherever it moves
position camera 0,100,-100
point camera object position x(2), object position y(2), object position z(2)
`track and display cylinders x,y, and z coordinates
set cursor 0,0
print \"Current X Position : \"
print CylinderPositionX#
set cursor 0,30
print \"Current Y Position : \"
print CylinderPositionY#
set cursor 0,60
print \"Current Z Position : \"
print CylinderPositionZ#
set cursor 0,90
print \"Current Frame Rate : \"
print screen fps()
sync
loop