Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Shifting a spherecast right or left?

Author
Message
gamergod88
7
Years of Service
User Offline
Joined: 28th Apr 2016
Location:
Posted: 10th Jun 2016 18:48 Edited at: 10th Jun 2016 18:51
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
micky4fun
9
Years of Service
User Offline
Joined: 15th Sep 2013
Location: uk essex
Posted: 10th Jun 2016 20:54 Edited at: 10th Jun 2016 20:58
Hi gamergod88

I am usually only about weekends due to long weekday working ,

Quote: " but how could I get the sphere cast slide to work with a rectangle?"

now that's no easy as far as I can make out , without using the physics commands
using the physics commands will do this , but I have not tried any of them yet.

my example only works with round or square shape players ,
I think that you might be how to use the raycast command along with some maths to do what you want .

But you have now set me a challenge so Sunday I will attempt to find a way , but please remember its me a novice trying to do this

thanks
mick
ps anyone knows a way please feel free to jump in and not make me look silly !
29 games
17
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 11th Jun 2016 17:15 Edited at: 11th Jun 2016 17:16
Try this:



This will only look right with boxes that are parallel with the xyz axis.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
micky4fun
9
Years of Service
User Offline
Joined: 15th Sep 2013
Location: uk essex
Posted: 11th Jun 2016 21:58
Hi All

Thanks 29 games , nice example
was trying to do something similar , but could not quite suss it out , your code is in my code bank.

I don't think its going to get much more dynamic without using the physics commands
today I was mucking about with Stab in the Dark's examples and modified he's basic world set up example
so I don't know if this is any help to you gamergod 88


all good fun
mick

Login to post a reply

Server time is: 2023-06-08 15:29:17
Your offset time is: 2023-06-08 15:29:17