loading an animated 3d character

Started by phodiS, November 15, 2018, 16:03:49

Previous topic - Next topic

phodiS

I am trying to load in a 3d animated character, but I keep getting the error
"failed to load object "knightwithshield.x"  I have the file in the root directory of the project directory   ,am I doing this right?.
Code (agk) Select

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Animation test" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
cameraMode = 1
SetCameraPosition(1,2000,180,1400) // startcam position
SetCameraRange( 1, 0.1, 600 )
SetCameraLookAt( 1, 0,40,0,0 )
setcamerafov(1,100)
rotateCameraglobaly(1,45)
type gametype
obj as integer
endtype



//Character

knight=LoadObjectWithChildren("knightwithshield.x")
SetObjectScalePermanent(knight,1,100,1)
SetObjectColor(knight,255,0,0,255)

while rc<300
d=random(0,360)
SetObjectRotation(obj,0,d,0)
playobjectanimation(obj,"knightwithshield.x",1,154,1,0)
x# = random(-3000,3000)
z# = random(-3000,3000)
y# = getobjectheightmapheight(1,x#,z#)
if y#>20
SetobjectPosition (obj,x#,y#,z#)
SetObjectCastShadow(obj,2)
rc=rc+1
endif   
endwhile

do
    // move the camera
speed# = 3.0
if ( GetRawKeyState( 16 ) ) then speed# = 5
if ( cameraMode = 1 ) then speed# = .5

if ( GetRawKeyState( 87 ) ) then MoveCameraLocalZ( 1, speed# )   //move forward
if ( GetRawKeyState( 83 ) ) then MoveCameraLocalZ( 1, -speed# )  //move back

if ( GetRawKeyState( 65 ) ) then RotateCameraLocalY( 1, -2 ) //rotate left
if ( GetRawKeyState( 68 ) ) then RotateCameraLocaly( 1, 2 )  //rotate right

if ( GetRawKeyState( 81 ) ) then RotateCameraLocalx( 1, speed# )
if ( GetRawKeyState( 69 ) ) then rotatecameralocalx( 1, -speed# )

if ( getvirtualbuttonstate(1) = 1 ) then MoveCameraLocalZ( 1, -speed# )
    if ( getvirtualbuttonstate(2) = 1 ) then MoveCameraLocalZ( 1, speed# )

// rotate the camera
if ( GetPointerpressed() )
        startx# = GetPointerX()
        starty# = GetPointerY()
        angx# = GetCameraAngleX(1)
        angy# = GetCameraAngleY(1)
        pressed = 1
    endif

    if ( GetPointerState() = 1 )
        fDiffX# = (GetPointerX() - startx#)/4.0
        fDiffY# = (GetPointerY() - starty#)/4.0

        newX# = angx# + fDiffY#
        if ( newX# > 89 ) then newX# = 89
        if ( newX# < -89 ) then newX# = -89
        SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
     endif
   
    // change camera mode
//    if ( GetVirtualButtonPressed(3) = 1 ) then cameraMode = 1-cameraMode
//    if ( cameraMode = 1 )
// stick camera to the terrain
x# = GetCameraX(1)
z# = GetCameraZ(1)
if GetObjectHeightMapHeight(1,x#,z#)>62
SetCameraPosition( 1, x#, GetObjectHeightMapHeight(1,x#,z#)+4, z# )
endif

    Print( ScreenFPS() )
    Sync()
loop

blinkok

create a directory in your project directory called "media" (lowercase)
Put your model in the "media" folder

phodiS

Hi there, I tried putting it into a media folder in the root directory of the program, but still get the same error. I have tried other models as well like the soldier.X and a robot.x all in the same folder .. is the actual command I am using right   >>>   knight=LoadObjectWithChildren("knightwithshield.x")   <<<   I tried with upper and lower cased ".x" as well with no luck...

blinkok

it worked ok for me. i did it with a simple object though. if you wanna pm me the model i could give it a try

phodiS