I cannot seem to get it to return the object ID of the character from the collision, I suspect there is something else that we are missing here...
Try this and see the jump/crouch impacting the debug capsule. You are correct the move set is typically on loading with exception to kinematic objects, the engine will think the object hasn't moved when it comes to the 3D physics. You need to stick with the SetObject3DPhysicsLinearVelocity() commands when moving around dynamic objects during runtime. And to be honest I'm not sure how this even impacts the character controller I am hoping it will handle all this (the crouch/jump actually looks quite effective here just need a fancy animated model.)
+ Code Snippet// Project: charAni
// Created: 23-07-28
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "charAni" )
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 )
SetPrintSize(20)
create3DPhysicsWorld(1)
Set3DPhysicsGravity(0, -10, 0)
SetAmbientColor(100, 100, 100)
`SetCameraPosition(1, 0, 500, -500)
`RotateCameraLocalX(1, -15)
SetCameraRange(1, 1, 5000)
ground = CreateObjectPlane(50, 50)
RotateObjectLocalX(ground, 90)
SetObjectColor(ground, 0, 102, 0, 255)
Create3DPhysicsStaticBody(ground)
box1 = CreateObjectBox(2, 2, 2)
SetObjectPosition(box1, -5, 7, 0)
SetObjectColor(box1, 252, 60, 12, 255)
Create3DPhysicsDynamicBody(box1)
box2 = CreateObjectBox(3, 6, 3)
SetObjectPosition(box2, 5, 3, 0)
SetObjectColor(box2, 50, 220, 255, 255)
Create3DPhysicsKinematicBody(box2)
dude = CreateObjectBox(1, 3.0, 0.5)
SetObjectPosition(dude, 0, 1.5, 0)
dudeAxis as integer = 1 //0 for X, 1 for Y (standing), 2 for Z (prone)
dudePosVec = CreateVector3(0.0, 1.5, 0.0) //Position Vector - offset from origin (model is 3 units high)
dudeRotVec = CreateVector3(0.0, 0.0, 0.0) //Rotation Vector (facing +z axis)
dudeCrouch as float = 0.5 //Amount to scale model when crouching
SetObjectTransparency(dude, 1)
SetObjectColor(dude, 50, 50, 50, 200)
Create3DPhysicsCharacterController(dude, dudeAxis, dudePosVec, dudeRotVec, dudeCrouch)
Debug3DPhysicsCharacterController(dude, 1)
a= 0
WalkVelocity as float
WalkVelocity= 20
finalRotation =0
x=0
do
print("move character with arrow")
print("jump with space")
print("crouch with ctrl")
print("ground ID = " + str(ground))
print("dynamic box1 ID = " + str(box1))
print("kinematic box2 ID = " + str(box2))
print("dude ID = " + str(dude))
x=0
Move3DPhysicsCharacterController(dude, x, WalkVelocity)
if GetRawKeyState(38)
x =1
Move3DPhysicsCharacterController(dude, x, WalkVelocity)
elseif GetRawKeyState(40)
x=2
Move3DPhysicsCharacterController(dude, x, WalkVelocity)
endif
if GetRawKeyState(39)
inc finalRotation, 3
Rotate3DPhysicsCharacterController(dude, finalRotation )
elseif GetRawKeyState(37)
dec finalRotation, 3
Rotate3DPhysicsCharacterController(dude, finalRotation )
endif
if (GetRawKeyState(32) = 1) //Space Bar
Jump3DPhysicsCharacterController(dude)
endif
if (GetRawKeyState(17) = 1) //Ctrl
Crouch3DPhysicsCharacterController(dude)
else
Stand3DPhysicsCharacterController(dude)
endif
if (GetObject3DPhysicsFirstContact(box1) = 1) //Character box has registered a collision in last step
obj_hit = GetObject3DPhysicsContactObjectB() //Get ID of object box collided with
print("box has made contact with " + str(obj_hit))
if (dude = obj_hit)
SetObjectColor(Box1, 255, 0, 0, 255)
Message("dude hit the box")
else
while (GetObject3DPhysicsNextContact() = 1) //Likely the first collision was the floor, keep looking for others
obj_hit = GetObject3DPhysicsContactObjectB()
print("box has also made contact with " + str(obj_hit))
if (dude = obj_hit)
SetObjectColor(Box1,255,0,0,255)
Message("dude hit the box")
endif
endwhile
endif
else
` SetObjectColor(Box1,255,255,255,255)
endif
Step3DPhysicsWorld()
Sync()
loop
Edit - The GetObjectWorldX() coordinates for the character object are updated when moving the character controller. So in some walk-over cases could use the object position, but I think it should be populated in the contact report...