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.

Dark GDK / Ray cast for gravity use

Author
Message
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 27th Jan 2012 20:19
Ok, time for another question! Haha I looked through all the old posts on ray casting, gravity, and collision but could not find a good answer to my question. I am using a ray cast to determine whether my player object is about to make contact with the floor. If not, the player object falls. If so, the player object stops and "rests" on the floor (rather, it hovers just above the floor). Here is the code I am using to check objects:



The ray cast does not seem to be working at all. I just continue to fall, straight through the floor of my level. Does anyone have any idea why the ray cast may not work? This code is not complete yet so I understand if there are bugs people may notice!!
Benjames8
14
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 1st Feb 2012 21:06
I suggest that you check like way past two units, like check 500 units or something, then check the SC_GetStaticCollisionY() or whatever and compare it to your objects current Y position.

Why???

Because you could be falling faster then the length of the raycast.. IE you'll fall right through the poly with no collision.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 1st Feb 2012 23:39
Quote: "int objectHit = SC_RayCast (0, old_x, old_y, old_z, old_x, old_y-2.0f, old_z, 0);
"

If at any time in the process of your game, the "old_y" is below the floor, this will not give you any "hit". I suggest you change you code slightly:
Your start position of the ray-cast should be somewhere above the player's position and the end AT the player's y-position. Then if the player goes through the floor (normally because of gravity), then your "objectHit" will be given the object#. Benjames8 has the right idea, use SC_getStaticCollisionY () to determine the distance from the start point to the collision (store that in a float). Now subtract that number from the "start point" and move your character UP that amount.

The fastest code is the code never written.
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 2nd Feb 2012 03:29
I see now. Yeah I have this portion of the code working now actually but I decided to scrap my own gravity in favor of a physics library because even though I got the gravity portion working I can't seem to keep myself from going through the walls, and even when I finally got THAT code fixed I couldn't seem to program the ability to climb stairs Does anyone have a quick code sample for that, or possibly an outline of what I need to do for stair-climbing? Maybe then I will endeavor to program my own physics
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Feb 2012 04:02
To make your char go up stairs, you can make a height test to see if the char can "step" on/over it. A 1ft height is about as large as most stairs get, so if the height is 1ft or less, then the char doesn't stop at the collision, but gets on top of it.

The fastest code is the code never written.
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 2nd Feb 2012 04:04
I tried that but the motion was very jerky for some reason. Plus when going down the stairs my gravity made me suspend in midair rather than follow the stairs down. What exactly should I do for going down? :/ Sorry that has been confusing the crap out of me. I tried to detect the stairs below me but I guess I was moving too fast to hit the steps? I'm so lost with stairs lol.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Feb 2012 17:43
That's the same problem I have when I do that. My solution is to make a limb of the stairs that's actually a ramp that goes just above the stair's steps. Make that limb hidden and do your check.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-23 00:14:44
Your offset time is: 2024-11-23 00:14:44