another way to move Objects
Posted: Tue Mar 25, 2014 10:08 pm
this a funny way to move objects, by only continuous applying :
PointJoint(joint, EntityID(surface), x, y, z, EntityID(object), x, y, z)
FreeJoint(joint)
with changing one of the coordinates as necessary
this is like a gecko walk . my next plan is to move the ball over a vertical wall, i have succeeded partially, i provide the horizontal walk as a showcase
press space to move the ball between wall 1 and wall 2
PointJoint(joint, EntityID(surface), x, y, z, EntityID(object), x, y, z)
FreeJoint(joint)
with changing one of the coordinates as necessary
this is like a gecko walk . my next plan is to move the ball over a vertical wall, i have succeeded partially, i provide the horizontal walk as a showcase
press space to move the ball between wall 1 and wall 2
Code: Select all
#CameraSpeed = 1
#joint = 200
#wall = 223
#wall2 = 225
#hat = 230
Define.f KeyX, KeyY, MouseX, MouseY
Global z.f
Global disp.f = 0.5
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
DesktopW=DesktopWidth(0)
DesktopH=DesktopHeight(0)
If OpenWindow(0, 0, 0, DesktopW, DesktopH, "press space to move the ball")
If OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Textures",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Scripts",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
WorldShadows(#PB_Shadow_Modulative, -1, RGB(127, 127, 127))
;Materials
;
CreateMaterial(0, LoadTexture(0, "Wood.jpg"))
GetScriptMaterial(1, "SphereMap/SphereMappedRustySteel")
CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
GetScriptMaterial(3, "Scene/GroundBlend")
; Ground
;
;CreatePlane(3, 500, 500, 5, 5, 5, 5)
CreateCube(3,1)
CreateEntity(3,MeshID(3),MaterialID(3), 0, 0, 0)
ScaleEntity(3,500,10,500)
EntityRenderMode(3, 0)
EntityPhysicBody(3, #PB_Entity_BoxBody, 0, 1, 1) ; note it has weight 0
CreateEntity(#wall,MeshID(3),MaterialID(3), 120, 20, 120)
ScaleEntity(#wall,30,10,50)
RotateEntity(#wall,-45,0,90)
EntityPhysicBody(#wall, #PB_Entity_StaticBody, 1, 1, 1) ; note it has weight 0
CopyEntity(#wall, #wall2)
MoveEntity(#wall2, -60, 20, -60)
RotateEntity(#wall2,-45,0,90)
EntityPhysicBody(#wall2, #PB_Entity_StaticBody, 1, 1, 1) ; note it has weight 0
; Objects
;
CreateSphere(2, 4, 6, 6)
ball = CreateEntity(#PB_Any, MeshID(2), MaterialID(1),0,7,0)
EntityPhysicBody(ball, #PB_Entity_SphereBody, 1.0, 0.3, 0.5)
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 254, 43, -137, #PB_Absolute)
CameraLookAt(0, 0, 20, 0)
RotateCamera(0, 0, 10,0,#PB_Relative)
; Skybox
;
SkyBox("desert07.jpg")
; Light
;
CreateLight(0, RGB(255, 255, 255), 100, 800, -500)
AmbientColor(RGB(20, 20, 20))
;WorldDebug(#PB_World_DebugBody )
ApplyEntityImpulse(ball, 0, 0.01, 0)
PointJoint(23, EntityID(3), 0, 5, 0, EntityID(ball), 0, 2, 0)
x.f = 0:z.f=0
Repeat
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space )
FreeJoint(23)
z.f+disp
x.f+disp
ApplyEntityImpulse(ball, 0, 0.01, 0)
PointJoint(23, EntityID(3), x, 5, z, EntityID(ball), 0, 2, 0)
If EntityCollide(ball, #wall)
disp = -0.5
ElseIf EntityCollide(ball, #wall2)
disp = 0.5
EndIf
EndIf
If KeyboardReleased(#PB_Key_C)
Debug CameraX(0):Debug CameraY(0):Debug CameraZ(0)
EndIf
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
EndIf
End