I am trying to detect whether the player is standing on the floor or an object (so they can jump) or is in the air.
I have searched the forums and read the docs and found that to do raycasting in dark physics, I need to use one of two undocumented commands:
[Edit: Now I have it working, I've edited the following so that other people searching have a reference]
Method 1: phy ray cast closest shape()
WORKS. Undocumented command, though is syntax-highlighted. Used in the "ProjectsDark PhysicsDemosRigid BodiesRay CastingRay Casting.dba" demo.
` Points to note:
` Parameters MUST be in (braces), or won't compile.
` Return value MUST be used, or won't compile.
` Last 3 params are a vector (ie, are relative to the 1st 3 params)
` The ray has no endpoint
ray = phy ray cast closest shape(PLAYER.X#, PLAYER.Y#, PLAYER.Z#, 0, -1, 0)
deleteme5 = phy get ray cast distance()
if phy get ray cast distance() < 5+PLAYER.Height/2
PLAYER.OnFloor = 1
PLAYER.SpeedY# = 0.0
endif
Method 2: phy ray cast all shapes()
WORKS. Undocumented command, mentioned in the documentation under "phy get ray cast hit()", and is syntax-highlighted. Used in the "ProjectsDark PhysicsTutorialsRay CastingRay Casting.dba" example. Possibly less efficient than the above since it will enumerate all colliding objects rather than just the first.
` Points to note:
` Parameters MUST be in (braces), or won't compile.
` Return value MUST be used, or won't compile.
` Last 3 params are a vector (ie, are relative to the 1st 3 params)
` The ray has no endpoint
ray = phy ray cast all shapes(PLAYER.X#, PLAYER.Y#, PLAYER.Z#, 0, -1, 0)
deleteme5 = phy get ray cast distance()
if phy get ray cast distance() < 5+PLAYER.Height/2
PLAYER.OnFloor = 1
PLAYER.SpeedY# = 0.0
endif
Method 3:
FAILS. Undocumented command, described in the update thread http://forum.thegamecreators.com/?m=forum_view&t=119906&b=30 but that's about it. Can't get this one to give a stable result. Works sometimes, but acts in the Z direction at other times. I may be using it wrong.
ray= phy ray cast(PLAYER.X#, PLAYER.Y#, PLAYER.Z#, PLAYER.X#, PLAYER.Y#-PLAYER.Height#, PLAYER.Z#, 0)
if phy get ray cast distance() < 5+PLAYER.Height/2
PLAYER.OnFloor = 1
PLAYER.SpeedY# = 0.0
endif
Method 4: phy get collision
FAILS. Undocumented command. Unfortunately, always returns false for a player controller, maybe because it is automatically moved so's not to collide with anything.
if phy get collision(PLAYER.Object, WORLD)
PLAYER.OnFloor = 1
endif
I find it amusing that the only ways to do this are with commands that are missing from the docs.
Yet another game programmer