i'm trying to make a working collision system for an adventure game, so i want the camera to follow the character
i use ngc v3.01
here is my code, but when i try to launch the program i get an error : invalid object number sent
#Constant NCULL_COUNTER_CLOCK 1
#Constant NCULL_CLOCK 2
#Constant NCULL_NONE 3
#Constant TYPE_NGC_ELLIP=1
#Constant TYPE_NGC_MESH=2
#Constant ELLIP_2_ELLIP=1
#Constant ELLIP_2_POLY=2
#Constant RESP_STICK=1
#Constant RESP_SLIDE=2
#Constant RESP_SLIDE_NO_SLOPES=3
#Constant RESP_SLIDE_NO_GRAV=4
#Constant RESP_SLIDE_NO_ACCEL=5
#Constant RESP_NONE=6
#Constant DYN_NO_RESP=1
#Constant DYN_RESP=2
#Constant DYN_RESP_NOTURN=3
rem sets our display mode
Set Window On
SET DISPLAY MODE 800, 600, 16
rem sync on
sync on : sync rate 60 : Autocam off
hide mouse
StartCollisionPRO(396214515, 164941351, 668663982)
StartCollisionDebugPRO()
SetCollisionExclusive( 1 )
#Constant TYPE_PLAYER = 3
#Constant TYPE_ENEMY = 4
#Constant TYPE_WORLD = 5
SetCollisionsPro( TYPE_PLAYER, TYPE_WORLD, ELLIP_2_POLY, RESP_SLIDE_NO_GRAV, DYN_RESP, 0 )
SetCollisionsPro( TYPE_PLAYER, TYPE_ENEMY, ELLIP_2_ELLIP, RESP_SLIDE, DYN_NO_RESP, 0 )
SetCollisionsPro( TYPE_ENEMY, TYPE_WORLD, ELLIP_2_POLY, RESP_SLIDE_NO_GRAV, DYN_RESP, 0 )
SetCollisionsPro( TYPE_ENEMY, TYPE_PLAYER,ELLIP_2_ELLIP, RESP_SLIDE, DYN_NO_RESP, 0 )
SetCollisionsPro( TYPE_ENEMY, TYPE_ENEMY, ELLIP_2_ELLIP, RESP_SLIDE, DYN_NO_RESP, 0 )
SetCollisionsPro( TYPE_FOLLOW_CAM, TYPE_WORLD, ELLIP_2_POLY, RESP_STICK, DYN_NO_RESP, 0 )
rem defines some global variables
global camera=0, cam_obj=1
rem Set this to the initial movement speed of the camera
global cam_speed# = 4.0
rem creates our camera and inits the properties
Set Camera Range 2,15000
make object sphere cam_obj, 2
Position Object cam_obj,0,15,0
Rotate Object cam_obj,0,-90,0
CollisionTypePRO( cam_obj, TYPE_FOLLOW_CAM )
SetObjRadiusPRO( cam_obj, 2, 2, 2 )
rem loads player objects
player=2
perso=3
load object "ethercap.x",perso
set object speed perso,50
make object sphere player,2
hide object player
CollisionTypePRO( player, TYPE_PLAYER )
SetObjRadiusPRO( player, 7, 20, 7 )
SetObjGravityPRO( player, 12 )
SetEllipOffsetPRO( player, 0, 11.2, 0 )
level = 4
load object "eglise.x",level
CollisionTypePRO( level, TYPE_WORLD )
do
UpdateFollowCamera()
UpdatePlayer()
xperso#=object position x(player)
yperso#=object position y(player)
zperso#=object position z(player)
Position Object perso,xperso#,yperso#,zperso#
RunCollisionPRO()
sync
loop
rem ***********
rem **** INPUT FUNCTIONS ********
rem ***********
function UpdatePlayer()
if leftkey()=1
YRotate Object player,wrapvalue(object angle y(player)-3.6)
endif
if rightkey()=1
YRotate Object player,wrapvalue(object angle y(player)+3.6)
endif
rem if upkey is pressed
if upkey()=1
loop object player,286,325
Move Object player,10
endif
rem if down key is pressed
if downkey()=1
loop object player,286,325
Move Object player, -10
endif
if upkey()=0 and downkey()=0
set object frame player,285
endif
endfunction
rem Follow-Character Camera handling function
function UpdateFollowCamera()
rem Get the positions of the main player object
xpos# = object position x(player)
ypos# = object position y(player)
zpos# = object position z(player)
rem position 'cam_obj' at the player object coords (a little up on the Y axis)
Position Object cam_obj, xpos#, ypos# + 30,zpos#
ResetObjPRO(cam_obj)
rem Get the wrapped Y angle of the player
yrot# = wrapvalue(object angle y(player))
rem Set the camera to follow the player object coords
set camera to follow camera, xpos#, ypos# + 25, zpos#, yrot#, 39, 6, 6.0, 0
rem Point the camera at the player object coords
point camera camera, xpos#, ypos# + 25, zpos#
rem Get the position/rotation of the camera
camx# = camera position x(camera) : camy# = camera position y(camera) : camz# = camera position z(camera)
camrx# = camera angle x(camera) : camry# = camera angle y(camera) : camrz# = camera angle z(camera)
rem place 'cam-obj' at the camera position/rotation
Position Object cam_obj, camx#, camy#, camz#
Rotate Object cam_obj, camrx#, camry#, camrz#
endfunction
www.whitechaos.tk