2D Top-Down Character Controller Using Rigidbody2D.Slide?

Is it (trivially) possible to create a 2d top-down character controller using the Rigidbody2D.Slide API?

I was rather excited when I found the Rigidbody2D.Slide API in the documentation but then was quickly disappointed when I realized it was tailored around platformer physics. Specifically, I was bummed when I realized that the Rigidbody2D.SlideMovement.surfaceUp required a non-zero-vector value. I was hoping a value of zero-vector would mean that it would slide on all axis using the surface normal.

Is there something I am missing with the configuration that would make this possible? Or will I have to essentially use the Rigidbody2D.Slide API as more of a “body cast” and implement the actual sliding myself? At that point, it would seem pointless to use the API and would be better off using the Rigidbody2D.Cast or Collider2D.Cast APIs.

Thanks.

1 Like

That’s a good observation, allowing this to be zero (degenerate) would mean it didn’t use the angle limit. Similar to how the anchor works.

I can look at adding that for you ASAP.

If you want to submit that as a bug, citing this thread, then I can use that bug report to push it through as well as you having a mathoe to track the change. If you do that, please send me the case incident ID.

3 Likes

Thanks for the quick reply. Excuse my ignorance, but do you want me to report a bug through the Unity Editor Help menu? (never reported a unity bug before)

Yes please. Don’t forget to mention this post and that you were asked by an employee to submit it. This should fast-track the process when CQA get around to seeing it.

I have submitted the report. The reference number is IN-91716.

Thanks again for the quick replies and willingness to resolve the issue.

1 Like

Thanks. Because it’s Xmas, it’s not likely this will be handed over to me until sometime early January.

1 Like

Not a problem. I can just implement my own (cruddy) collide and slide while I’m prototyping.

You can take a look at my PhysicsExamples2D repo.

In that there’s a top-down controller example here with the basic Kinematic controller example script here which is close to what the basic “Slide” stuff does.

Note that in that old example there, a new feature hasn’t been used which is the ability to cast from a specific position so you don’t have to continually update the position of the rigidbody during interations.

Overloads lower down the pages:

Also, this might be useful to you where I shared the C++ source code for the Slide method.

It’s pretty simple really: Issues with Rigidbody2D.Slide and gravity/jumping - #7 by MelvMay

Thanks, I’ll take a look at these resources.

1 Like

Just a heads-up to say that today I received the bug report from our CQA. The progress can be followed here: Unity Issue Tracker - Rigidbody2D.Slide API does not have the needed configuration when creating a 2D Top-Down character controller

Thanks again for the report.

1 Like

Just a heads-up to say that today I’ve fixed this issue and I’ll be getting the fix out ASAP. You can use the link above to watch for your case landing in future releases.

Here’s your test-case when I set the “surfaceUp” to (0,0): Screen capture - 007c746b10f643261f8f3cd751957110 - Gyazo

Thanks again for the report.