@blinkok
I think with work
dodgem cars can be done like this
// Project: carnivalGames
// Created: 2018-10-20
// show all errors
SetErrorMode(2)
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 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 ) // since version 2.0.22 we can use nicer default fonts
create3DPhysicsWorld()
SetCameraFOV( 1, 60 )
type point
x as float
y as float
z as float
endtype
#constant swidth = 1024
#constant sheight = 768
floorObj=100
SetCameraPosition(1, 0,60, -170)
CreateObjectBox(floorObj,150,1,150)
SetObjectPosition(floorObj,0,-18,10)
Create3DPhysicsStaticBody(floorObj)
SetObjectShapeBox(floorObj)
CreateObjectBox(2,5,5,150)
SetObjectPosition(2,-75,-16,10)
Create3DPhysicsStaticBody(2)
CreateObjectBox(3,5,5,150)
SetObjectPosition(3,75,-16,10)
Create3DPhysicsStaticBody(3)
CreateObjectBox(4,150,5,5)
SetObjectPosition(4,0,-16,85)
Create3DPhysicsStaticBody(4)
CreateObjectBox(5,150,5,5)
SetObjectPosition(5,0,-16,-65)
Create3DPhysicsStaticBody(5)
CreateObjectBox(200,4,4,10)
SetObjectColor(200,255,0,0,255)
SetObjectPosition(200,30,-14,10)
direction as point
Create3DPhysicsDynamicBody(200)
direction = GetObjectDirectionVector( 200, 2 )
//SetObject3DPhysicsLinearVelocity(200, 0, 0,1, 100 )
SetObject3DPhysicsLinearVelocity(200, direction.x,direction.y,direction.z, 100 )
SetObject3DPhysicsAngularVelocity(200,0,90,0,100 )
do
print(GetObjectZ(200))
Print(GetObject3DPhysicsAngularVelocityX(200))
Print(GetObject3DPhysicsLinearVelocityZ( 200 ) )
if GetObject3DPhysicsLinearVelocityZ(200)<.1
Delete3DPhysicsBody(200)
Create3DPhysicsDynamicBody(200)
direction=GetObjectDirectionVector(200,2)
SetObject3DPhysicsLinearVelocity(200, direction.x,direction.y,direction.z, 100 )
SetObject3DPhysicsAngularVelocity(200,0,90,0,150 )
endif
if GetRawKeyState(38)=1 Then MoveCameraLocalZ(1,1)
if GetRawKeyState(40)=1 Then MoveCameraLocalZ(1,-1)
if GetRawKeyState(39)=1 Then MoveCameraLocalX(1,1)
if GetRawKeyState(37)=1 Then MoveCameraLocalX(1,-1)
Step3DPhysicsWorld()
sync()
loop
// 1 = FWD, 2 = REV, 3 = UP, 4 = DOWN, 5 = RIGHT, 6 = LEFT
Function GetObjectDirectionVector( objID as integer, direction as integer )
vector as point
tempObj as integer
tempObj = CreateObjectBox( 1.0, 1.0, 1.0 )
SetObjectPosition( tempObj, GetObjectWorldX( objID ), GetObjectWorldY( objID ), GetObjectWorldZ( objID ) )
SetObjectRotation( tempObj, GetobjectWorldAngleX( objID ), GetobjectWorldAngleY(objID), GetobjectWorldAngleZ( objID ) )
select direction
case 1 :
MoveObjectLocalZ( tempObj, 1.0 )
endcase
case 2 :
MoveObjectLocalZ( tempObj, -1.0 )
endcase
case 3 :
MoveObjectLocalY( tempObj, 1.0 )
endcase
case 4 :
MoveObjectLocalY( tempObj, -1.0 )
endcase
case 5 :
MoveObjectLocalX( tempObj, 1.0 )
endcase
case 6 :
MoveObjectLocalX( tempObj, -1.0 )
endcase
endselect
vector.x = GetObjectWorldX( tempObj ) - GetObjectWorldX( objID )
vector.y = GetObjectWorldY( tempObj ) - GetObjectWorldY( objID )
vector.z = GetObjectWorldZ( tempObj ) - GetObjectWorldZ( objID )
DeleteObject(tempObj)
EndFunction vector
Calculating the angle vector needs allot of work but it demonstrates one red bumper car moving around by itself
bouncing off the walls setting direction and angular vectors
add a second car increase the height of walls and increase the velocity and you get something like this
// Project: carnivalGames
// Created: 2018-10-20
// show all errors
SetErrorMode(2)
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 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 ) // since version 2.0.22 we can use nicer default fonts
create3DPhysicsWorld()
SetCameraFOV( 1, 60 )
type point
x as float
y as float
z as float
endtype
#constant swidth = 1024
#constant sheight = 768
floorObj=100
SetCameraPosition(1, 0,60, -170)
CreateObjectBox(floorObj,150,1,150)
SetObjectPosition(floorObj,0,-18,10)
Create3DPhysicsStaticBody(floorObj)
SetObjectShapeBox(floorObj)
CreateObjectBox(2,10,10,150)
SetObjectPosition(2,-75,-16,10)
Create3DPhysicsStaticBody(2)
CreateObjectBox(3,10,10,150)
SetObjectPosition(3,75,-16,10)
Create3DPhysicsStaticBody(3)
CreateObjectBox(4,150,10,10)
SetObjectPosition(4,0,-16,85)
Create3DPhysicsStaticBody(4)
CreateObjectBox(5,150,10,10)
SetObjectPosition(5,0,-16,-65)
Create3DPhysicsStaticBody(5)
CreateObjectBox(200,4,4,10)
SetObjectColor(200,255,0,0,255)
SetObjectPosition(200,30,-14,10)
direction as point
Create3DPhysicsDynamicBody(200)
direction = GetObjectDirectionVector( 200, 2 )
//SetObject3DPhysicsLinearVelocity(200, 0, 0,1, 100 )
SetObject3DPhysicsLinearVelocity(200, direction.x,0,direction.z, 200 )
SetObject3DPhysicsAngularVelocity(200,0,90,0,100 )
CreateObjectBox(201,4,4,10)
SetObjectColor(201,255,0,0,255)
SetObjectPosition(201,-30,-14,10)
Create3DPhysicsDynamicBody(201)
direction = GetObjectDirectionVector( 201, 1 )
//SetObject3DPhysicsLinearVelocity(200, 0, 0,1, 100 )
SetObject3DPhysicsLinearVelocity(201, direction.x,direction.y,direction.z, 200 )
SetObject3DPhysicsAngularVelocity(201,0,90,0,100 )
do
if GetObject3DPhysicsLinearVelocityZ(200)<.1
Delete3DPhysicsBody(200)
Create3DPhysicsDynamicBody(200)
direction=GetObjectDirectionVector(200,2)
SetObject3DPhysicsLinearVelocity(200, direction.x,0,direction.z, 200 )
SetObject3DPhysicsAngularVelocity(200,0,90,0,150 )
endif
if GetObject3DPhysicsLinearVelocityZ(201)<.1
Delete3DPhysicsBody(201)
Create3DPhysicsDynamicBody(201)
direction=GetObjectDirectionVector(201,1)
SetObject3DPhysicsLinearVelocity(201, direction.x,0,direction.z, 200 )
SetObject3DPhysicsAngularVelocity(201,0,90,0,150 )
endif
if GetRawKeyState(38)=1 Then MoveCameraLocalZ(1,1)
if GetRawKeyState(40)=1 Then MoveCameraLocalZ(1,-1)
if GetRawKeyState(39)=1 Then MoveCameraLocalX(1,1)
if GetRawKeyState(37)=1 Then MoveCameraLocalX(1,-1)
Step3DPhysicsWorld()
sync()
loop
// 1 = FWD, 2 = REV, 3 = UP, 4 = DOWN, 5 = RIGHT, 6 = LEFT
Function GetObjectDirectionVector( objID as integer, direction as integer )
vector as point
tempObj as integer
tempObj = CreateObjectBox( 1.0, 1.0, 1.0 )
SetObjectPosition( tempObj, GetObjectWorldX( objID ), GetObjectWorldY( objID ), GetObjectWorldZ( objID ) )
SetObjectRotation( tempObj, GetobjectWorldAngleX( objID ), GetobjectWorldAngleY(objID), GetobjectWorldAngleZ( objID ) )
select direction
case 1 :
MoveObjectLocalZ( tempObj, 1.0 )
endcase
case 2 :
MoveObjectLocalZ( tempObj, -1.0 )
endcase
case 3 :
MoveObjectLocalY( tempObj, 1.0 )
endcase
case 4 :
MoveObjectLocalY( tempObj, -1.0 )
endcase
case 5 :
MoveObjectLocalX( tempObj, 1.0 )
endcase
case 6 :
MoveObjectLocalX( tempObj, -1.0 )
endcase
endselect
vector.x = GetObjectWorldX( tempObj ) - GetObjectWorldX( objID )
vector.y = GetObjectWorldY( tempObj ) - GetObjectWorldY( objID )
vector.z = GetObjectWorldZ( tempObj ) - GetObjectWorldZ( objID )
DeleteObject(tempObj)
EndFunction vector
but I think with a car with a rounded front end it would work better with the physics and not get stuck in the corners
the main reason I cranked the velocity
and I think getting/setting the angular velocity separate from velocity might work better.
Anyone watching this thread that's achieved this using a better method?
HAHAHA This project proving to be quite a large thing to complete lol There is just so many games that can be added
maybe if Dodgem cars eventuates it could be a bonus game
fubar