I must add a second entity (1), Line 70;-EntityPhysicBody(0, #PB_Entity_BoxBody, 50) ; Dont work
And lines 98 & 99.EntityPhysicBody(1, #PB_Entity_BoxBody, 50)
See also this example, i use the same work around, but collisions do not always work correctly. And after I shoot on the pyramid, collisions with the tank does not work at all.; Replace l'entity 1 à la même position que l'entity 0 pour gérer les collisions !
RotateEntity(1, NodePitch(0), NodeYaw(0), NodeRoll(0),RotationAbs)
EntityLocate(1, EntityX(0), EntityY(0), EntityZ(0))
Code: Select all
#PB_Engine_Space_Local=1
#PB_Engine_Space_Parent=2
#PB_Engine_Space_World=4
#PB_Engine_Absolute_Rotation=8
#PB_Engine_Relative_Rotation=16
#PB_Engine_Quaternion_Rotation=32
#PB_Engine_Euler_Rotation=64
Global RotationAbs = #PB_Engine_Euler_Rotation | #PB_Engine_Absolute_Rotation
Global RotationRel = #PB_Engine_Euler_Rotation | #PB_Engine_Relative_Rotation
#PlayerSpeed = 4
#Camera = 0
Macro NEW_X(x, Angle, Distance)
((x) + Cos(Radian(Angle)) * (Distance))
EndMacro
Macro NEW_Z(z, Angle, Distance)
((z) + Sin(Radian(Angle)) * (Distance))
EndMacro
Define.f KeyX, KeyY, MouseX, MouseY
Declare CreatePyramideCube(x.f, y.f, z.f, MeshPyramide, PyramideMaterial)
Declare GestionCamera()
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "char")
WorldShadows(#PB_Shadow_Modulative)
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
;-Create Sol
Sol = CreatePlane(#PB_Any, 100, 100, 20, 20, 20, 20)
CreateEntity (5, MeshID(Sol), #PB_Material_None)
EntityRenderMode(5, 0) ; Disable shadow casting for this entity as it's our plan
EntityPhysicBody(5, #PB_Entity_StaticBody)
;-Create Pyramide
MeshPyramide = CreateCube(#PB_Any, 10)
Nb=7
Size=20*3+0.5
For j = 0 To Nb
For i= 0 To Nb-j
CreatePyramideCube(j*(Size/2)+i*Size, (Size/2)+(j*Size), 800, MeshPyramide, 6)
Next i
Next j
;-Corps
CreateCube(0, 20)
CreateNode(0)
CreateEntity(0, MeshID(0), #PB_Material_None)
ScaleEntity(0,8,2,4)
MoveEntity(0,0,20,0)
AttachNodeObject(0,EntityID(0),#PB_Node_Entity)
RotateNode(0, 0, 90, 0, RotationAbs)
;-EntityPhysicBody(0, #PB_Entity_BoxBody, 50) ; Dont work
;-Pour les collisions
CopyEntity(0, 1)
ScaleEntity(1,8,2,4)
MoveEntity(1,0,20,0)
EntityPhysicBody(1, #PB_Entity_BoxBody, 50)
;-Camera
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 0, 400, 350)
CameraLookAt(0,NodeX(0),NodeY(0),NodeZ(0))
;-Light
CreateLight(0,RGB(255,255,255),100,500,0)
AmbientColor(RGB(0,0,0))
Repeat
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
NodeLocate(0, NEW_X(NodeX(0), NodeYaw(0), #PlayerSpeed), NodeY(0), NEW_Z(NodeZ(0), NodeYaw(0), #PlayerSpeed))
ElseIf KeyboardPushed(#PB_Key_Down)
NodeLocate(0, NEW_X(NodeX(0), NodeYaw(0), -#PlayerSpeed), NodeY(0), NEW_Z(NodeZ(0), NodeYaw(0), -#PlayerSpeed))
EndIf
If KeyboardPushed(#PB_Key_Left)
RotateNode(0,0, -1.2, 0, RotationRel)
ElseIf KeyboardPushed(#PB_Key_Right)
RotateNode(0,0, 1.2 ,0, RotationRel)
EndIf
EndIf
; Replace l'entity 1 à la même position que l'entity 0 pour gérer les collisions !
RotateEntity(1, NodePitch(0), NodeYaw(0), NodeRoll(0),RotationAbs)
EntityLocate(1, EntityX(0), EntityY(0), EntityZ(0))
GestionCamera()
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Procedure CreatePyramideCube(x.f, y.f, z.f, MeshPyramide, PyramideMaterial)
Block = CreateEntity(#PB_Any, MeshID(MeshPyramide), #PB_Material_None, x, y, z)
ScaleEntity(Block, 6, 6, 6)
EntityPhysicBody(Block, #PB_Entity_BoxBody, 50)
ProcedureReturn Block
EndProcedure
Procedure.f curveValue(actuelle.f, Cible.f, P.f)
If P > 1000.0
P = 1000.0
EndIf
ProcedureReturn (actuelle + ( (Cible - actuelle) * P / 1000.0))
EndProcedure
Procedure.f CurveAngle(oldangle.f,newangle.f, increments.f)
If increments>1
If (oldangle+360)-newangle<newangle-oldangle
oldangle=360+oldangle
EndIf
If (newangle+360)-oldangle<oldangle-newangle
newangle=360+newangle
EndIf
oldangle=oldangle-(oldangle-newangle)/increments
EndIf
If increments<=1
ProcedureReturn newangle
EndIf
ProcedureReturn oldangle
EndProcedure
Procedure GestionCamera()
Define.f Px, Py, Pz, Pv, Pv1
Static AngleCamera.f
Pv = 10
Pv1 = 50
AngleCamera = CurveAngle(AngleCamera, NodeYaw(0) + 180, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(NodeX(0), AngleCamera, 360), Pv1)
Py = CurveValue(CameraY(#Camera), NodeY(0) + 150, Pv1)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(NodeZ(0), AngleCamera, 360), Pv1)
CameraLocate(#Camera, Px, Py, Pz)
CameraLookAt(#Camera, NodeX(0), NodeY(0), NodeZ(0))
EndProcedure