Hi there,
I've tried to make this simple sliding collision program with the level (attached) and it works fine except for when the object OR camera collides with the corner of the walls - when it does the object seems to become jittery.
I would much appreciate any help with resolving this issue.
Many thanks!
Rem Project: movement
Rem Created: Sunday, February 03, 2013
Rem ***** Main Source File *****
`set camera
set camera range 1,300000000000
`make world
make matrix 1,2500,2500,15,15
`make character object
make object cube 1,50
sc_SetupObject 1,0,0
`make a level object
load object "level3.x",3
xrotate object 3,270
fix object pivot 3
scale object 3,500,500,500
position object 3,1250,0,1250
sc_setupComplexObject 3,0,0
`declare variables
global max_speed as integer
global spd# as double float
global x# as double float
global z# as double float
global cay# as double float
global cx# as double float
global cz# as double float
global camMouse as integer
global delay as integer
dist# = 100
`MAIN LOOP
SYNC ON : SYNC RATE 60 : DO
`Get old positions for collisoin later
oldx# = camera position x()
oldy# = camera position Y()
oldz# = camera position z()
oldxx# = object position x(1)
oldyy# = object position Y(1)
oldzz# = object position z(1)
vx# = 0
vz# =0
set cursor 0,0
print vx#
print vz#
`HANDLE SPEED
if keystate(42) = 1 then max_speed = 10 else max_speed = 2.5
if keystate(17)=0 and keystate(30)=0 and keystate(31)=0 and keystate(32)= 0
spd# = curvevalue(0.0,spd#,5.0)
else
spd# = curvevalue(max_speed,spd#,5.0)
endif
`MOVEMENT OF CHARACTER
if keystate(17) = 1
yrotate object 1, curveangle(camera angle y(),object angle y(1),5.0)
endif
if keystate(30) = 1
yrotate object 1, curveangle(camera angle y()-90,object angle y(1),5.0)
endif
if keystate(31) = 1
yrotate object 1, curveangle(camera angle y()+180,object angle y(1),5.0)
endif
if keystate(32) = 1
yrotate object 1, curveangle(camera angle y()+90,object angle y(1),5.0)
endif
x# = oldxx# + vx#
y# = object position y(1)
z# = oldzz# + vz#
`POSITIONING CAMERA
`if either left/right keys are pressed and camMouse (shows that camera is controlled by mouse i.e. arrows) then camMouse = 1
if KEYSTATE(75) = 1 and camMouse = 0 then camMouse = 1
if Keystate(77) = 1 and camMouse = 0 then camMouse = 1
`if cam NOT controlled by mouse.. delay = 0, camera angle y variable = 0, position camera just behind character and point at object
if camMouse = 0
delay = 0
cay# = 0
position camera CURVEVALUE(x#,camera position x(),15.0), object position y(1)+150, CURVEVALUE(z#-dist#,camera position z(),15.0)
point camera object position x(1), object position y(1), object position z(1)
endif
`if cam IS controlled by mouse.. (changed to Arrow keys instead of mouse)
if camMouse = 1
`if keystate is left/right then increase the angle variable (cay#) : reset the delay too so that if the player presses the left/right AGAIN (i.e.
`*while* the delay timer is running) then the delay will be cancelled
if keystate(75)=1 then cay# = cay# - 3 : delay = 0
if keystate(77)=1 then cay# = cay# + 3 : delay = 0
`calculate the new x and z values for the camera based on the above camera angle y()
cx# = NewXvalue(object position x(1),cay#+180,dist#)
cz# = NewZvalue(object position z(1),cay#+180,dist#)
`position the camera + use curvevalue to make smooth transition during turning
position camera Curvevalue(cx#,camera position x(),5.0), object position y(1)+150, Curvevalue(cz#,camera position z(),5.0)
point camera object position x(1),object position y(1),object position z(1)
endif
`** handle collision for player object **
collide1 = sc_sphereCast(0,oldxx#,oldyy#,oldzz#,x#,y#,z#,25,0)
IF collide1 > 0
x# = sc_getCollisionSlideX()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
ENDIF
position object 1,x#,y#,z#
`** handle collision for camera**
cx# = camera position x()
cy# = camera position y()
cz# = camera position z()
`if there's a collision update the object position AND the camera so that the camera sticks on the world
collide2 = sc_sphereCast(0,oldx#,oldy#,oldz#,cx#,cy#,cz#,25,0)
if collide2 > 0
cx# = sc_getCollisionSlideX()
cz# = sc_getCollisionSlideZ()
position camera cx#,cy#,cz#
endif
sync : loop
if memblock exist(1) then delete memblock 1
Hello World Tommorrow