I was given this code by user Mickey4Fun and it works great, but how could I get the sphere cast slide to work with a rectangle? I have already asked Mickey and got no response.
// Project: 3d collision test
// Created: 2016-06-04
// set window properties
SetVirtualResolution(1280,800)
SetWindowSize( 1280, 800, 0 )
SetDisplayAspect(1280 / 800.0)
SetScissor(0,0,0,0)
SetOrientationAllowed( 1, 1, 1, 1 )
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)
// make player and colour him red
player=1
CreateObjectBox(player,10,10,10)
SetObjectColor(player,255,255,255,100)
SetObjectPosition(player,-90,0,0)
SetObjectCollisionMode(player,0)
SetObjectColor(player,255,0,0,255)
// make platform
platform=2
CreateObjectBox(platform,100,5,30)
SetObjectColor(platform,255,255,255,100)
SetObjectPosition(platform,0,-40,0)
// set the radius of the player at 5 as the player is 10x10x10
radius=5
do
// get player input
joystick_y# = GetJoystickY()*-1
joystick_x# = GetJoystickX()*1
player_x#=player_x#+joystick_x#
player_y#=player_y#+joystick_y#
// save old position
player_oldx# = GetObjectX(player)
player_oldy# = GetObjectY(player)
// check to see if player hits platform
object_hit = ObjectSphereSlide(platform, player_oldx#, player_oldy#,0.0,player_x#, player_y#,0.0,radius)
// if player touches platform , make him stay there
if object_hit <> 0
player_x# = GetObjectRayCastSlideX(player)
player_y# = GetObjectRayCastSlideY(player)
endif
// position the player
SetObjectPosition(player, player_x#, player_y#, 0.0)
sync()
loop