playMaker

Author Topic: Ground detection, going through the floor  (Read 2115 times)

DennisJensen

  • Full Member
  • ***
  • Posts: 104
Ground detection, going through the floor
« on: May 02, 2018, 04:23:22 AM »
Hi PM forum,

We are big fans of the forum and playmaker, our own game is 90% playmaker, KnightOut, which is coming to switch and PC later this year.

I have a problem which I been struggling with back and forth. I need some inputs on this. So basically we use RayCasting for our character, when he is in the air we translate him Y to give him gravity when he moves we translate in X. When we run the game it's running at 60 FPS, smooth and everything is good. However, to prevent our character from penetrating the ground we sat the maximum allowed timestep low to 0.02. He is moving every frame, and that made it possible that he couldn't penetrate the ground/floor but the issue arises when people have a bad computer or where streaming it would maybe run at 30 FPS. Since it's limited to every frame it would run in slow motion. Not great.

So by increasing our maximum allowed timestep and set our translation to fixed update, we are able to get the same speed of the character in 30 fps or 15 fps for that sake. However, we now get the problem of penetrating the ground since our character moves really fast he is able, between frames, to go undetected through the floor.

It's a problem we been having again and again and it would be great to find a proper solution. Right now our distance for ground detection is set to 0.4 which means if it's less he will be on the ground, I could make that higher and in that way minimize the issue but I have a feeling it would still happen. I also did a hard fix, that if the character goes through the ground he will pop back up, but it's not a good solution since we have floor levels as well, and he can go through those floors. At least it's not game breaking with that fix.

Cheers
/Dennis
Game Designer, CEO, Artist
http://2ndStudio.com

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
Re: Ground detection, going through the floor
« Reply #1 on: May 02, 2018, 09:29:36 AM »
Had a very similar issue where I had bullets passing through objects - I don't have my solution/actions on hand, but here's the script I based it on:

http://wiki.unity3d.com/index.php?title=DontGoThroughThings

Basically, just get the object's position every frame, then fire a raycast back to its position on the previous frame, and if it hits something, then do something - fire an event, or push the player/object back to its previous position etc.

Not sure how intensive it is, but it seems to work for me, so hopefully work's for your situation too.

DennisJensen

  • Full Member
  • ***
  • Posts: 104
Re: Ground detection, going through the floor
« Reply #2 on: May 03, 2018, 04:36:24 AM »
@Kathar
Thank you. Since we don't use rigid body on our character it's not really viable.

At the moment I managed to get it running pretty well without issues at 30 fps, but it's something I need to test more. I extended the distance for detecting a collision and then I played around with the maximum allowed timestep. I think it's a balance between those.

Before it would happen all the time, so it's in the right direction :)

Just a heads up, we had issues with OBS causing our game to run at 30 fps, and if the player has a bad computer and sets the quality at the highest it's nice to know that it would still run, at a bad frame rate though. That's why I'm working on this issue.
Game Designer, CEO, Artist
http://2ndStudio.com

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
Re: Ground detection, going through the floor
« Reply #3 on: May 03, 2018, 08:15:36 AM »
I didn't actually use it with rigidbodies either, just applied to the same logic to my movement code, seems to work. Glad it sounds like you got a solution working though - game looks great!