Right, still frustrated with this, it is true I had the sizes wrong,which I adjusted in my editor,but I still got this flicker, so I took the code that created the character controller from your example, taking out the animation commands as I wasnt using them: firstly the model:
https://drive.google.com/open?id=0B4KG5czzbkfldmZxUkR4UW1FSFE
This model is just the soldier exported from fragmotion as a .obj, so without the anim frames.
Now the code:
// Project: test
// Created: 2016-07-04
// set window properties
SetWindowTitle( "test" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Create3DPhysicsWorld()
global rotationInc as float
global finalRotation as float
global WalkVelocity as float
global RunVelocity as float
global CameraDistance#=650
floorBoxID = CreateObjectBox( 1000.0, 12.0, 1000.0 )
//SetObjectImage( floorBoxID, floorTexID, 0 )
//SetObjectColor( floorBoxID, 112, 100, 100, 255 )
SetObjectLightMode( floorBoxID, 1 )
SetObjectPosition( floorBoxID, 0.0, 0.0, 0.0 )
//This command creates a static physics body for the floor box with a triangle mesh collision shape.
//A static physics body has no mass and does not get moved.
Create3DPhysicsStaticBody( floorBoxID )
//This 3D Physics command changes the collision shape to a primative box shape since we do not need the accuracy of
// polygon collision for just a box. The physics body is still static.
SetObjectShapeBox( floorBoxID ) //
playerobject=loadobject("man.obj")
SetObjectPosition( playerobject, 0.0, 10.0, 0.0 )
SetObjectRotation( playerobject, 0, 90, 0 )
CreateCharacterController( playerobject )
do
setcameraposition(1,getobjectx(playerobject),getobjecty(playerobject),getobjectz(playerobject)+CameraDistance#/2)
setcameralookat(1,getobjectx(playerobject),getobjecty(playerobject),getobjectz(playerobject),0)
Print( ScreenFPS() )
CharacterControllerInput(playerobject)
Step3DPhysicsWorld() //required for updating physics.
Sync()
loop
function CreateCharacterController( objID as integer )
characterOffsetVec = CreateVector3( 0.0, 36.0, 0.0 )
objectOrientationVec = CreateVector3( 0.0, 0.0, -1.0 )
Create3DPhysicsCharacterController( objID, 1, characterOffsetVec, objectOrientationVec, 0.75 )
DeleteVector3( characterOffsetVec )
DeleteVector3( objectOrientationVec )
rotationInc = 1.0
WalkVelocity = 72.0
RunVelocity = 140.0
endfunction
function CharacterControllerInput( objID as integer )
if GetKeyboardExists()
//Stops movement when no key is pressed.
Move3DPhysicsCharacterController( objID, 0, WalkVelocity )
//W Key Forwards
if GetRawKeyState( 87 )
Move3DPhysicsCharacterController( objID, 1, WalkVelocity )
endif
if GetRawKeyState( 67 ) and GetRawKeyPressed( 87 ) or GetRawKeyState( 87 ) and GetRawKeyPressed( 67 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 2073, 2101, 1, 0.25 )
elseif GetRawKeyPressed( 87 ) or ( GetRawKeyReleased( 67 ) and GetRawKeyState( 87 ) )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
if GetRawKeyReleased( 87 )
//PlayObjectAnimation( objID, "Animation", 3002, 3547, 1, 0.25 )
endif
//Strafe Held and forward released
if GetRawKeyPressed( 87 ) and GetRawKeyState( 65 )
endif
//S key Backwards
if GetRawKeyState( 83 )
Move3DPhysicsCharacterController( objID, 2, WalkVelocity )
endif
if GetRawKeyPressed( 83 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
if GetRawKeyReleased( 83 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 3002, 3547, 1, 0.25 )
endif
//A Key Strafe Left
if GetRawKeyState( 65 )
// if GetObjectAnimationTime( objID ) > 635 and GetObjectAnimationTime( objID ) < 643
// Move3DPhysicsCharacterController( objID, 3, WalkVelocity - 65.0 )
// else
Move3DPhysicsCharacterController( objID, 3, WalkVelocity - 40.0 )
endif
endif
if GetRawKeyPressed( 65 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
if GetRawKeyReleased( 65 )
//PlayObjectAnimation( objID, "Animation", 3002, 3547, 1, 0.25 )
endif
//To handle release of left strafe with forward still held
if GetRawKeyReleased( 65 ) and GetRawKeyState( 87 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
//To handle release of left strafe with backwards still held
if GetRawKeyReleased( 65 ) and GetRawKeyState( 83 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
//Strafe Left Held and forward released
if GetRawKeyState( 65 ) and GetRawKeyReleased( 87 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
//Strafe left Held and backwards released
if GetRawKeyState( 65 ) and GetRawKeyReleased( 83 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
//D Key Strafe Right
if GetRawKeyState( 68 )
//if GetObjectAnimationTime( objID ) > 635 and GetObjectAnimationTime( objID ) < 643
//Move3DPhysicsCharacterController( objID, 4, WalkVelocity - 65.0 )
//else
Move3DPhysicsCharacterController( objID, 4, WalkVelocity - 40.0 )
//endif
endif
if GetRawKeyPressed( 68 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
if GetRawKeyReleased( 68 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 3002, 3547, 1, 0.25 )
endif
//To handle release of Right strafe with forward still held
if GetRawKeyReleased( 68 ) and GetRawKeyState( 87 )
//SetObjectAnimationSpeed( objID, 30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
//To handle release of Right strafe with backwards still held
if GetRawKeyReleased( 68 ) and GetRawKeyState( 83 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 1290, 1320, 1, 0.25 )
endif
//Strafe Right Held and forward released
if GetRawKeyState( 68 ) and GetRawKeyReleased( 87 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
//Strafe Right Held and backwards released
if GetRawKeyState( 68 ) and GetRawKeyReleased( 83 )
//SetObjectAnimationSpeed( objID, -30.0 )
//PlayObjectAnimation( objID, "Animation", 611, 643, 1, 0.25 )
endif
//SpaceBar Jump
if GetRawKeyPressed( 32 )
Jump3DPhysicsCharacterController( objID )
//PlayObjectAnimation( objID, "Animation", 2283, 2333, 0, 0.25 )
endif
//C_Key And W_Key Crouch and move forward or just crouch
if GetRawKeyState( 67 ) and GetRawKeyState( 87 )
//if GetObjectAnimationTime( objID ) > 2094 and GetObjectAnimationTime( objID ) < 2104
//Move3DPhysicsCharacterController( objID, 1, WalkVelocity - 65.0 )
Move3DPhysicsCharacterController( objID, 1, WalkVelocity - 40.0 )
endif
//Q Key For Rotate
if GetRawKeyState( 81 )
finalRotation = finalRotation - rotationInc
endif
//E Key For Rotate
if GetRawKeyState( 69 )
finalRotation = finalRotation + rotationInc
endif
Rotate3DPhysicsCharacterController( objID, finalRotation )
endfunction
This code is chunks of yours with a more simple main loop, just the basics needed to see what is going on!
If you run this, keep pressing a until the character falls off the edge, now when I do this, the character falls, but I get a flicker and see more than 1 model!
However if I put the sync() before the Step3DPhysicsWorld() command, the flicker vanished.
Hail to the king, baby!