playMaker

Author Topic: Rigid body controller steps/bumps  (Read 1421 times)

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Rigid body controller steps/bumps
« on: September 29, 2019, 11:10:04 AM »
So I'm setting up a basic rigid body controller. Right now I'm wondering how to proceed with the fact that any tiny bump on the ground means the character gets stuck.

What's a basic principle that can be used to sort this out?

Right now the only thing I can think of is something a ray cast or collider system when it finds it the object is blocked at ground level, then checks if slightly higher is clear, then does an impulse up?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5945
    • View Profile
    • jinxtergames
Re: Rigid body controller steps/bumps
« Reply #1 on: September 29, 2019, 12:40:12 PM »
Hi,
I assume that you have a box collider and 3d.

You can change the collider to a Capsule Collider and use some constraints so it does not fall over. now you should not have issues getting stuck on every small bump.

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #2 on: September 29, 2019, 10:48:15 PM »
Hi,
I assume that you have a box collider and 3d.

You can change the collider to a Capsule Collider and use some constraints so it does not fall over. now you should not have issues getting stuck on every small bump.
Actually I am using a capsule already. Maybe it's not every bump it gets stuck on, but is getting stuck on very small steps.

I am already doing constraints to not tip over.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5945
    • View Profile
    • jinxtergames
Re: Rigid body controller steps/bumps
« Reply #3 on: October 01, 2019, 08:45:01 AM »
Hi.
If you have steps like stairs, usually they are set with slanting collider.

Could you show some images where/when player gets stuck (from scene view and showing all colliders)

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #4 on: October 01, 2019, 10:14:24 AM »
I was hoping to avoid sloping colliders so I don't have to do so much designing on every little edge on a level.

I attached an example on a small step I would like the character to just hop up, rather than placing a slope over.

I also attached a diagram showing the idea I'm working on to build a kind of hoping up steps with stages system.
Basically the red box represents a collider, used to figure out what the character may need to hop up.
Then there are 'stages'. These are also colliders which go a little in front of the character and extend above their head a little too. It would work something like this;

* Red collider at ground level triggers if level enters

* Player needs to be grounded and there needs to be movement input, so you can't keep floating up and won't hop repeatedly by standing too close to a wall

* Checks the stage 1 trigger. If it's empty, it means nothing is in the way from barely off the floor to over the player's head. So goes to an action to do a small hop. This is for minor bumps.

* If stage 1 had something in it, it checks stage 2. This is a bit higher off the floor so if it's empty, it goes to an action with a little bit bigger hop.

* If stage 2 had something in it, checks stage 3, if empty does a bigger hop again.

etc.

If it fails the last stage it figures that the obstacle is too big to hop over so do nothing.

I think I can get it to work but it feels wonky and inaccurate. I mean don't know how I will pair the hopping force with the stages other than lots of trial and error observing what happens with different numbers.

ViRiX Dreamcore

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #5 on: October 01, 2019, 12:31:49 PM »
Normally in situations like this, the designer will have a simplified version of the level that is just used for colliding.

Thore

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #6 on: October 01, 2019, 01:00:22 PM »
I’ve implemented this that way:

1) steps are prefabs with a ramp shaped collider.
2) the character has a small ray in facing direction and parallel to the ground that detects obstacles. On hit with an obstacle, the character hops up and forward a little.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5945
    • View Profile
    • jinxtergames
Re: Rigid body controller steps/bumps
« Reply #7 on: October 01, 2019, 07:32:19 PM »
Hi.
some  Raycasts that Thore mentioned can be a good idea, maybe only do the ray's when moving forward.

You can do 1st a level 3 raycast, then a level 2, then level 1 and loop back when no hit (with a next frame event in between.

daniellogin

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #8 on: October 05, 2019, 12:45:59 AM »
Finally had some time give it a try the way I described. Honestly I'm a little surprised, since it's such a fiddly solution. I sort of just assumed something better existed, since it's no problem at all for the Unity character controller to have step height set. When people talk about that you can make a character controller with rigid body or Unity module, I think more emphasis needs to be made on that steps will be an issue.

So yeah, I got it to work by using a series of colliders to vary the hopping up height, but I have a another idea which may be more accurate (still fiddly to trial and error set up though).

1) Collider to feel for an obstacle
2) Ray cast barely off the ground. Basically starting where the character could get stuck at.
3) If it fails, the ray casting object moves higher by a very small interval. The minimum that could matter to make a difference.
4) Repeats this process until the ray object meets it maximum height (and so says don't jump) or it finds the correct height it needs to clear.
5) It then does some kind of basic math operation to use the distance the ray moved up to multiply the jump force applied. This is where it will be fiddly to find the right base force float to be multiplied.

Doing it this way may make for a smoother and more dialed in system, since using the colliders is limited to the amount of steps you manually add in, and also has the forces manually added in rather than being a consistent formula based exactly on the height which needs to be cleared.

This is just a theory though and my current simple mini game doesn't need the extra effort to try the above. I would probably try it though if I made a more serious rigid body character.

As a side note, the only reason why I went with a rigid for this little game is that it's controlled by a single analog stick (so just movement, no look), and so I needed the character to rotate to the direction of travel. After some brief research the only way I found to do this was to use the direction of force.
« Last Edit: October 05, 2019, 12:49:11 AM by daniellogin »

Thore

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Rigid body controller steps/bumps
« Reply #9 on: October 05, 2019, 02:48:04 AM »
Finally had some time give it a try the way I described. Honestly I'm a little surprised, since it's such a fiddly solution. I sort of just assumed something better existed, since it's no problem at all for the Unity character controller to have step height set. When people talk about that you can make a character controller with rigid body or Unity module, I think more emphasis needs to be made on that steps will be an issue.  […]

Maybe there is a better solution, but when I looked, it’s even more fiddly than you imagine. Because controlling the character semi-automatically also requires to switch control of set velocity in a timed fashioned. You likely run into the same problem: when applying forward movement to overcome the step, you need to briefly disable set velocity in the player-controlled character movement (for example by going to a state that doesn’t set it). Otherwise, the character will not overcome the step. Fun!