i just bought dp and it's pretty cool. i'm playing around with the vehicle and the terrain static object and it's very easy, and stable.
i have an attached screenshot showing this. i think i can easily create a racing game now, previously unimaginable.
i'm having a bit of trouble with the camera place ment. it's just too jerky.
Here's my code:
Rem Project: Runaround
Rem Created: 10/26/2007 8:56:00 AM
Rem ***** Main Source File *****
sync on : sync rate 30 : phy start
phy set gravity 0,-100,0
concrete=1
phy make material concrete,"concrete"
phy set material static friction concrete,0.75
phy set material dynamic friction concrete,1
phy set material restitution concrete,1
phy build material concrete
load image "media/terrain/texture.bmp", 1
load image "media/terrain/detail.tga", 2
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "media/terrain/map.bmp" ` set the heightmap
set terrain scale 1,3, .6, 3 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -0.25, 0, .75, .25, .75, .5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 1, 2 ` base and detail texture
build terrain 1 ` finally build the terrain
phy make rigid body static terrain 1, concrete
`make object cube 2,10
`phy make box character controller ID, x#, y#, z#, size x#, size y#, size z#, up, step#, slope limit#
`phy make box character controller 2, 500, 100, 500, 5, 5, 5, 1, 1, 45
load object "beach.x", 2
position object 2, 500, 20, 500
rotate limb 2, 0, 0, -90, 0
phy create vehicle 2
phy add vehicle body 2, 2.2, 0.6, 0.75, 0.0, 0.6, 0.0
phy add vehicle wheel 2, 5, 1.5, 0.3, 1.1, 0.6, 0.2, 0, 0
phy add vehicle wheel 2, 7, 1.5, 0.3, -1.1, 0.6, 0.2, 0, 1
phy add vehicle wheel 2, 3, -1.5, 0.3, -1.1, 0.6, 0.2, 1, 0
phy add vehicle wheel 2, 9, -1.5, 0.3, 1.1, 0.6, 0.2, 1, 1
phy set vehicle max motor 2, 600
phy set vehicle steering delta 2, 0.1
phy set vehicle max steering angle 2, 0.4
phy set vehicle auto 2, 1
phy set vehicle suspension spring 2,200
phy build vehicle 2
cameraObj = 100
make object cube cameraObj, 10
turn object right 100, 100
position camera 385,50,100
do
if spacekey() = 1 THEN end
`controlCameraWithMouseKeyBoard(0, 1, 3)
`position camera camera position x(0), 10+get terrain ground height(1,camera position x(0), camera position z(0)),camera position z(0)
`controlCharacter(2,50)
`positionCameraAsObject(2, 0)
`set camera to follow object position x ( 2 ), object position y ( 2 ), object position z ( 2 ), 0, 6, 4, 1, 0
`gosub driveCar
`setCamera(0, 2, 20, 0, 0)
ezRotateFunction(2, 100, 0, -10, 5, 0)
`controlCameraObjectAndCamera(0, cameraObj, 2, 35)
phy set vehicle auto 2, 1
update terrain
phy update
sync
loop
function controlCameraObjectAndCamera(camNum, cameraObj, objNum, offset)
objPosX# = object position x(objNum)
objPosY# = object position y(objNum)
objPosZ# = object position z(objNum)
objRotX# = object angle x(objNum)
objRotY# = object angle y(objNum)
objRotZ# = object angle z(objNum)
text 0,0,str$(objPosX#)+" : "+str$(objPosY#)+" : "+str$(objPosZ#)
position object cameraObj, objPosx#, objPosY#, objPosZ#
rotate object cameraObj, object angle x(cameraObj), objRotY#, object angle z(cameraObj)
move object cameraObj, offset
`objPosX# = object position x(cameraObj)
`objPosY# = object position y(cameraObj)
`objPosZ# = object position z(cameraObj)
`text 0,15,str$(objPosX#)+" : "+str$(objPosY#)+" : "+str$(objPosZ#)
`position camera 0, objPosX#, objPosY#, objPosZ#
endfunction
function controlCharacter(objNum, speed)
if shiftkey() = 1 THEN speed = speed *10
if upkey() = 1 OR keystate(20) = 1 THEN phy move character controller objNum,speed
if downkey() = 1 OR keystate(34) = 1 THEN phy move character controller objNum,speed*-1
if keystate(20) = 0 AND keystate(34) = 0 THEN phy move character controller objNum,0
if keystate(33) THEN yrotate object objNum, object angle y(objNum)-2
if keystate(35) THEN yrotate object objNum, 2 + object angle y(objNum)
if keystate(19) THEN move object left objNum, speed
if keystate(21) THEN move object right objNum, speed
`if upkey() = 1
` phy move character controller objNum, speed
`else
` phy move character controller objNum, speed
`endif
endfunction
function controlCameraWithMouseKeyBoard(cameraNum, objectNum, speed)
rotate camera cameraNum, camera angle x(cameraNum)+(mousemovey()/speed), camera angle y(cameraNum)+(mousemovex()/speed), 0
cx# = camera angle x(cameraNum) : cy# = camera angle y(cameraNum)
`w,s,a,d*****forward,back,left,right
if upkey() = 2 OR keystate(17) = 1 then xrotate camera cameraNum, 0 : move camera cameraNum, speed : xrotate camera cameraNum, cx#
if downkey() = 2 OR keystate(31) = 1 then xrotate camera cameraNum, 0 : move camera cameraNum, -1*speed : xrotate camera cameraNum, cx#
if leftkey() = 2 OR keystate(30) = 1 THEN yrotate camera cameraNum, cy#-90 : move camera speed : yrotate camera cameraNum, cy#
if rightkey() = 2 OR keystate(32) = 1 THEN yrotate camera cameraNum, cy#+90 : move camera speed : yrotate camera cameraNum, cy#
if wrapvalue(camera angle x(cameraNum))>40 and wrapvalue(camera angle x(cameraNum))<180 then xrotate camera cameraNum, 40
if wrapvalue(camera angle x(cameraNum))>180 and wrapvalue(camera angle x(cameraNum))<280 then xrotate camera cameraNum, 280
endfunction
function positionCameraAsObject(objectNum, cameraNum)
objPosX# = object position x(objectNum)
objPosY# = object position y(objectNum)
objPosZ# = object position z(objectNum)
objRotX# = object angle x(objectNum)
objRotY# = object angle y(objectNum)
objRotZ# = object angle z(objectNum)
position camera cameraNum, objPosX#, objPosY#, objPosZ#
rotate camera cameraNum, objRotX#, objRotY#, objRotZ#
endfunction
function setCamera(camNum, objNum, space, height, offset)
objPosX# = object position x(objNum)
objPosY# = object position y(objNum)
objPosZ# = object position z(objNum)
objRotY# = wrapvalue(object angle y(objNum)+360)
camPosX# = camera position x(camNum)
camPosY# = camera position y(camNum)
camPosZ# = camera position z(camNum)
camRotX# = camera angle x(camNum)
camRotZ# = camera angle z(camNum)
rotate camera camNum, camRotX#, objRotY#, camRotZ#
position camera camNum, objPosX#, objPosY#+height, objPosZ#
move camera space * -1
point camera camNum, objPosX#, objPosY#+offset, objPosZ#
endfunction
function ezRotateFunction(objNum, objNumTwo, camNum, offsetX#, offsetY#, offsetZ#)
`Set EZrotate up with ship's current rotation
EZro_SetEuler OBJECT ANGLE X(objNum),OBJECT ANGLE Y(objNum),OBJECT ANGLE Z(objNum)
`Set EZrotate up with ship's current position
EZro_SetPos OBJECT POSITION X(objNum),OBJECT POSITION Y(objNum),OBJECT POSITION Z(objNum)
`!!! Find world coordinates of point from offset settings !!!
EZro_FindPointFromOffset offsetX#, offsetY#, offsetZ#
`!!! Position Camera at Calculated position !!!
POSITION CAMERA camNum, EZro_GetOffsetX(),EZro_GetOffsetY(),EZro_GetOffsetZ()
`Set the camera's rotation equal to the ship's rotation
Point CAMERA camNum, OBJECT position X(objNum),OBJECT position Y(objNum)+4,OBJECT position Z(objNum)
endfunction
remstart
driveCar:
if upkey ( ) = 1
phy set vehicle motor force 2, 200
else if downkey ( ) = 1
phy set vehicle motor force 2, 0.0
else if phy get vehicle motor force ( 2 ) <> 0.0
phy set vehicle motor force 2, 0.0
endif
steeringAngle# = phy get vehicle steering angle ( 2 )
steeringDelta# = phy get vehicle steering delta ( 2 )
if leftkey ( ) = 1
if steeringAngle# > ( -1.0 + steeringDelta# )
steeringAngle# -= steeringDelta# / 2
endif
else if rightkey ( ) = 1
if steeringAngle# < ( 1.0 – steeringDelta# )
steeringAngle += steeringDelta# / 2
endif
else
if steeringAngle# > 0.0
steeringAngle# = steeringAngle# - steeringDelta# * 2
if steeringAngle# < 0
steeringAngle# = 0.0
endif
else if steeringAngle < 0.0
steeringAngle# = steeringAngle# + steeringDelta# * 2
if steeringAngle# > 0
steeringAngle# = 0.0
endif
endif
endif
phy set vehicle steering angle 2, steeringAngle#
return
remend
it's not exactly clean or anything like that, lol. but the function that I'm using is called function ezRotateFunction(objNum, objNumTwo, camNum, offsetX#, offsetY#, offsetZ#)
function ezRotateFunction(objNum, objNumTwo, camNum, offsetX#, offsetY#, offsetZ#)
`Set EZrotate up with ship's current rotation
EZro_SetEuler OBJECT ANGLE X(objNum),OBJECT ANGLE Y(objNum),OBJECT ANGLE Z(objNum)
`Set EZrotate up with ship's current position
EZro_SetPos OBJECT POSITION X(objNum),OBJECT POSITION Y(objNum),OBJECT POSITION Z(objNum)
`!!! Find world coordinates of point from offset settings !!!
EZro_FindPointFromOffset offsetX#, offsetY#, offsetZ#
`!!! Position Camera at Calculated position !!!
POSITION CAMERA camNum, EZro_GetOffsetX(),EZro_GetOffsetY(),EZro_GetOffsetZ()
`Set the camera's rotation equal to the ship's rotation
Point CAMERA camNum, OBJECT position X(objNum),OBJECT position Y(objNum)+4,OBJECT position Z(objNum)
endfunction
This function uses the ez rotate commands. it works fine--it does what it's supposed to, but its very shaky. Anyone know of a better way to position a camera behind an object?