Moving Platform Collision Example


(Posted 1 year ago) RonTek

platform collisions by Warner, ported to OpenB3DMax

Blitz3D BlitzMax Moving Platform Collision

'minib3d platform Collisions by Warner
'OpenB3DMax port by RonTek

Framework Openb3dMax.B3dglgraphics
Import Brl.Random
?Not bmxng
Import Brl.Timer
?bmxng
Import Brl.TimerDefault
?

Graphics3D 800, 600, 0, 2

CreateLight()

Local piv:TPivot, cube:TMesh

'everything is a child of this pivot
piv = CreatePivot()

'create camera
Local cam:TCamera = CreateCamera(piv)
MoveEntity cam, 0, 5, -15
CameraClsColor cam, 0, 0, 255

'create cube (=platform)
cube = CreateCube(piv)
ScaleEntity cube, 4, 4, 4
PositionMesh cube, 0, -1.35, 0
EntityType cube, 2
MoveEntity cube, 0, 0.4, 0
'MoveEntity cube, 0, 2, 0 '<--rotation

'create ground
Local ground:TEntity = createplane2(piv)
EntityColor ground, 0, 255, 0
MoveEntity ground, 0, -1, 0
EntityType ground, 2

'create sphere (=player)
Local sphere:TMesh = CreateSphere(8, piv)
EntityColor sphere, 255, 0, 0
PositionEntity sphere, -10, 1, 0
EntityType sphere, 1

'set collisions
Collisions 1, 2, 2, 3

Local hh#
Local p#
Repeat

    'move sphere
    If KeyDown(KEY_LEFT) MoveEntity sphere, -0.2, 0, 0 
    If KeyDown(KEY_RIGHT) MoveEntity sphere, 0.2, 0, 0
    If KeyDown(KEY_UP) MoveEntity sphere, 0,0, 0.2 
    If KeyDown(KEY_DOWN) MoveEntity sphere, 0, 0,-0.2
    MoveEntity sphere, 0, -1, 0
    UpdateWorld 0 'normal collisions

    p :+ 2
    hh# = Sin(p) * 0.1

'   piv.px = cube.px '<-rotation
'   piv.py = cube.py
'   piv.pz = cube.pz

    EntityParent cube, Null

'   TurnEntity piv, 0, 1, 0 '<-rotation

    'move everything, except the cube
    MoveEntity piv, 0, -hh, 0 '<-disable for rotation
    EntityParent cube, piv

    UpdateWorld 'platform collisions

    RenderWorld
    Flip
Until KeyHit(KEY_ESCAPE)
End

'--------------------------------------------------------------------------------------------------------------------------------------
'                                               CreatePlane()
'--------------------------------------------------------------------------------------------------------------------------------------
Function CreatePlane2:TEntity(parent:TEntity=Null)

    Local mesh:TMesh = CreateMesh(parent)
    Local surf:TSurface = CreateSurface(mesh)

    Local s# = 900.0
    AddVertex surf, -s, 0,  s, -s,  s
    AddVertex surf,  s, 0,  s,  s,  s
    AddVertex surf,  s, 0, -s,  s, -s
    AddVertex surf, -s, 0, -s, -s, -s
    AddTriangle surf, 0, 1, 2
    AddTriangle surf, 0, 2, 3
    VertexNormal surf, 0, 0, 1, 0
    VertexNormal surf, 1, 0, 1, 0
    VertexNormal surf, 2, 0, 1, 0
    VertexNormal surf, 3, 0, 1, 0

    Return mesh

End Function
(Posted 1 year ago) markcwm commented:

Thanks Ron, looks good! I never saw this one before.

If you're wondering why there's no activity from me at the moment it's because I've got sciatica. I should be okay in a few more weeks but for now I'm not doing anything.

Be well.

(Posted 1 year ago) RonTek commented:

Sure thing Mark! Yes, it is and just came across this sometime ago on the old forums when looking for an easy moving collision solution. Ah I see. I hope it's not something serious and get well the soonest! speedy recovery!

Reply To Topic

Please log in to reply