@Stab : thanks again, you're right.
In my previous test, my character-object didn't work with kinematic and dynamic object, but in my new test, it works.
Here is a new code (I have use one of your examples for the character
) :
Do you know how the character can move the yellow box ?
And How I can detect collision between the player (objid =1) and the others objects ?
Because it's a character, I think I can't use contact.
// Project: 3d_collisionbox
// Created: 2015-12-17
SetErrorMode(2)
SetWindowTitle( "3d_collisionbox" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Create3DPhysicsWorld()
//ground
CreateObjectPlane(3,300,300)
SetObjectRotation(3,90,0,0)
SetObjectColor(3,100,100,100,255)
Create3DPhysicsStaticBody(3)
// player
CreateObjectBox(1,15,45,15)
SetObjectPosition(1,0,150,0)
characterOffsetVec = CreateVector3( 0.0, 0.0, 0.0 )
objectOrientationVec = CreateVector3( 0.0, 0.0, 0.0 )
Create3DPhysicsCharacterController( 1, 1, characterOffsetVec, objectOrientationVec, 0.75 )
DeleteVector3( characterOffsetVec )
DeleteVector3( objectOrientationVec )
Set3DPhysicsCharacterControllerPosition(1,getobjectx(1),getobjecty(1),getobjectz(1))
// yellow box
u = 15
CreateObjectBox(2,u,u,u)
SetObjectPosition(2,60,8,60)
Create3DPhysicsDynamicBody(2)
SetObjectColor(2,200,150,0,255)
//SetObject3DPhysicsMass(2,5)
//SetObject3DPhysicsFriction(2,0)
//SetObject3DPhysicsDamping(2,100,100)
// move box
u = 20
CreateObjectBox(4,u,10,u)
SetObjectPosition(4,-60,20,-60)
Create3DPhysicsKinematicBody(4)
SetObjectColor(4,50,150,200,255)
SetObject3DPhysicsMass(4,0)
SetCameraPosition(1,0,150,-200)
SetCameraLookAt(1,0,0,0,0)
WalkVelocity = 75
local finalRotation as float
rotationInc = 1
objID = 1
a=0
do
Print( str(ScreenFPS())+" | Collision : "+str(id) )
oldX = GetObjectX(1)
oldy = GetObjectY(1)
oldZ = GetObjectZ(1)
Step3DPhysicsWorld()
inc a
SetObjectPosition(4,-60+sin(a)*50,GetObjectY(4),GetObjectZ(4))
if GetRawKeyPressed( 27 )
end
endif
move = 0
jump = 0
if GetKeyboardExists()
//Stops movement when no key is pressed.
Move3DPhysicsCharacterController( objID, 0, WalkVelocity)
//up key Forwards
if GetRawKeyState( 38 )
Move3DPhysicsCharacterController( objID, 1, WalkVelocity )
move = 1
endif
//down Backwards
if GetRawKeyState( 40 )
Move3DPhysicsCharacterController( objID, 2, WalkVelocity )
move = 1
endif
//Q Key For Rotate
if GetRawKeyState( 37 )
finalRotation = finalRotation - rotationInc
Rotate3DPhysicsCharacterController( objID, finalRotation )
endif
//E Key For Rotate
if GetRawKeyState( 39 )
finalRotation = finalRotation + rotationInc
Rotate3DPhysicsCharacterController( objID, finalRotation )
endif
// R Strafe Left
if GetRawKeyState( 82 )
Move3DPhysicsCharacterController( objID, 3, WalkVelocity )
move = 1
endif
// T Strafe Right
if GetRawKeyState( 84 )
Move3DPhysicsCharacterController( objID, 4, WalkVelocity )
move = 1
endif
//SpaceBar Jump
if GetRawKeyPressed( 32 )
Jump3DPhysicsCharacterController(objID)
endif
Rotate3DPhysicsCharacterController( objID, finalRotation )
Endif
if move>0
NewX = GetObjectX(1)
Newy = GetObjectY(1)
NewZ = GetObjectZ(1)
endif
// id = ObjectSphereCast(2, oldx, oldy, oldz, NewX, Newy, NewZ,12) // it works fine
id = ObjectSphereCast(0, oldx, oldy, oldz, NewX, Newy, NewZ, 20) // if I use this line, the id is strange (1 or 100001 or 100002 but not 3 or 4)
Sync()
loop
For the moment, I use : id = ObjectSphereCast(objid, oldx, oldy, oldz, NewX, Newy, NewZ,20) for all type of object (I change objId by their id), but I would like to use a "general" code (like : id = ObjectSphereCast(0,oldx, oldy, oldz, NewX, Newy, NewZ,20))
Thank you for your help.
Thanks again
AGK2 tier1 - http://www.dracaena-studio.com