blinks code worked well and enabled me to produce
https://forum.thegamecreators.com/thread/223651
I particularly love the way even loop de loops were possible
but I see no reason why you cant make use of the charactercontrollers and simplify it allot like below
SetErrorMode(2)
#constant acceleration#=.05 //used to calclate the carSpeed#
#constant maxCarSpeed#=20.0 //The Maximum speed the carBlock will move
#constant minCarSpeed#=0.0 //The Minimum speed the carBlock will move
#constant AccelerationFactor#=.25 //the speed your car accelerates at
#constant DecelerationFactor#=.05 //the braking factor
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
screenWidth As Float
screenHeight As Float
screenAspect As Float
screenWidth = GetDeviceWidth()
screenHeight = GetDeviceHeight()
// set window properties
SetWindowTitle("Vehicle physics with playercontrollers")
SetOrientationAllowed(0, 0, 1, 1) // allow both portrait and landscape on mobile devices
SetWindowSize(screenWidth, screenHeight, 0, 0)
SetWindowAllowResize(1) // allow the user to resize the window
// set display properties
SetVirtualResolution(screenWidth, screenHeight) // doesn't have to match the window
SetSyncRate(25, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1)
create3DPhysicsWorld()
box=CreateObjectSphere(2, 16, 16)
SetObjectColor(box,200,200,200,255)
SetObjectPosition(box,0,2,0)
//RotateObjectLocalz(box,90)
//SetCameraPosition(1, 0, 0, -3)
///SetCameraLookAt(1, 0, 0, 0, 0)
createCharacterController(box)
ground=CreateObjectPlane(200,200)
SetObjectImage(ground,CreateGrid(screenWidth,screenHeight), 0)
RotateObjectLocalX(ground,90)
Create3DPhysicsStaticBody(ground)
ramp=CreateObjectPlane(10,40)
SetObjectColor(ramp,200,0,0,255)
SetObjectPosition(ramp,0,-.025,10)
RotateObjectLocalX(ramp,65)
Create3DPhysicsStaticBody(ramp)
global velocity as float
do
print (velocity)
updatePlayerMovement(box)
SetCameraPosition(1,GetObjectWorldX(box),GetObjectWorldY(box)+5,GetObjectWorldZ(box)-5)
Sync()
loop
function createCharacterController(objID as integer)
//This vector is the offset of the model center from origin.
//For example a model 72 units tall standing at origin is 36 units offset on the y axis.
//This allows for models of different sizes.
characterOffsetVec = CreateVector3( 0.0, 0.0, 0.50 )
//This vector indicates the axis your model faces forward.
//For example if your model faces down the - Z axis use this vector.
objectOrientationVec = CreateVector3( 0.0, 0.0, 0.0 )
//The crouchScale parameter is 0.0 to 1.0, for examle 0.75 is 75% of the models standing height.
Create3DPhysicsCharacterController( objID, 1, characterOffsetVec, objectOrientationVec, 0.90 )
DeleteVector3( characterOffsetVec )
DeleteVector3( objectOrientationVec )
endfunction
function updatePlayerMovement(player as integer)
if GetRawKeyState(KEY_LEFT) //strafe left
Rotate3DPhysicsCharacterController(player,GetObjectAngleY(player)-2)
endif
if GetRawKeyState(KEY_RIGHT) //strafe right
Rotate3DPhysicsCharacterController(player,GetObjectAngleY(player)+2)
endif
if GetRawKeyState(KEY_UP) //move forward
//velocity=velocity+1.0
velocity=velocity+((maxCarSpeed#-velocity)*AccelerationFactor#)
if velocity>maxCarSpeed# then velocity=maxCarSpeed#
else
velocity=velocity-((maxCarSpeed#-velocity)*DecelerationFactor#+0.1)
if velocity<minCarSpeed# then velocity=minCarSpeed#
endif
Move3DPhysicsCharacterController(player,1,velocity)
Step3DPhysicsWorld() //needs to be called prior to below and any camera adjustments
endfunction
function CreateGrid(screenWidth,screenHeight)
SetClearColor(0x70, 0x70, 0x70)
ClearScreen()
size = screenWidth/ 32
green=MakeColor(0,200,0)
DrawBox(0, 0, screenWidth, screenHeight, green,green,green,green, 1)
for i=0 to screenWidth step size
DrawLine(i, 0, i, screenHeight, 200,0,0)
next
for i=screenHeight to 0 step -size
DrawLine(0, i, screenWidth, i, 200,0,0)
next
render()
img = GetImage(0, 0, screenWidth, screenHeight)
ClearScreen()
endfunction img
There was also a great example I forget who by (possibly santman) that had a car running over a terrain quite well
PS This is a very friendly forum so if you have difficulties and post an example people often love to help unlike other forums