I’m trying to implement one-way platforms you can jump off by using Physics2D.IgnoreCollision to let the player descend and reenable collision when they stop touching said platform (detected using a trigger). I’m using Rigidbody2D.Slide to move my player, but it seems it’s not taking into account Physics2D.IgnoreCollision (Physics2D.GetIgnoreCollision confirms the returned slideHit should be ignored for the player collider), making my approach unfeasible. Is this the intended behavior?
Thanks spiney199, but layer masks won’t help here as I’m trying to filter-out a specific collider, not the whole layer. Since It’s a RigidBody2D method (rather than Physics2D one) I expected it to have enough information to realize which colliders should be ignored, but It may very well be not the case.
Right, sorry about that. Let me clarify.
I’ve got the following scene:
The player (in black) has a CapsuleCollider2D to handle collisions and a BoxCollider2D with isTrigger checked to find out whether they are still inside a one-way platform they are descending from (details about this process not relevant in my opinion, correct me if I’m wrong).
When I want to descend from OneWayPlatform I tell the player’s CapsuleCollider2D to ignore collisions with the platform’s collider like this: Physics2D.IgnoreCollision(PlayerCollider, platformCollider);
This allows the player to fall through it, but if I try moving to the left (using RigidBody2D.Slide) I hit a collision (as shown in the log)
Moving right find’s no collision (I assume because that’s the direction the physics system wants to move the collider to).
This is the code handling the movement:
GroundSlideMovement has the following configuration:
In case it may help, this is the configuration of the player’s RigidBody2D:
Please keep in mind in this scenario I’ve removed the Platform Effector 2D I’ll need to get the full functionality as I want to focus my question in the interaction between RigidBody2D.Slide and Physics2D.IgnoreCollision.
So if i am understanding correctly, you want the player to be able to drop below platforms while on them, kinda like some old Mario games or other platformers. Correct?
If so, your current method seems like an overly complicated way of doing that.
Here is a quick video of how-to go up through (as you know using PlatformEffectors) but also drop below. Maybe at least check it out and see if the end result is what you are looking for and see if you can apply it to your issue.
I have honestly never even heard of the Rigidbody2D.Slide method before nor seen anyone ask about it. So there is definitely is something i could be missing as to why you are trying to use it and when it is valuable to use. But i am just trying to diagnose your functionality problem and solve it regardless of current implementation.
Yes, it’s relatively new. Rigidbody2D.Slide is part of the new functionality released in 2023.1 and can make it easier to write your own character controllers without having to perform lots of manual physics queries.
The thing is, it’s still essentially using physics queries (Rigidbody2D.Cast) i.e. filtering contacts by layer-mask is the primary mechanism so there’s no scope to use things like IgnoreCollisions right now, same as any other physics query.
That said, I don’t see any good reason why it’d be bad to also implicit check any the IgnoreCollisions that are active but to get it fixed in 2023 I’d need to add it as a bug so I’d need a bug report made for it. If you want to do that and provide me with the incident number, that’d be great. Also, please refer to my post stating you’ve been asked to submit a report so that QA don’t reject it (it’s not intended to use that option).
Whilst I’m at it, it might also be worth using the layer-overrides too.
Thanks for your advice Cornysam. Yes, I already checked that tutorial and it’s in fact where I got the idea to use Physics2D.IgnoreCollision from. I cannot just rely on a simple time-out though, because as seen in the test scene I want to support one-way platforms where you can stay partially overlapped for as long as you want.
I can see Rigidbody2D.Slide is not yet very popular, possibly because it’s not yet part on any LTS version. It is a really cool feature, though. It automates the process of keeping the player snapped to the ground (with configurable limits, of course) and even prevents undesirable bounces when hitting a wall. I’ve been trying to replicate this behavior manually for days and it get quiet complex and ugly very fast.
I see, thanks al lot for the explanation MelvMay. I’ll report it as soon as I can. Meanwhile I’ll check these layer overrides you mentioned and see if they can help me.
Very interesting, as soon as i hit enter and reviewed your original post, i was like, maybe he wants to stay within the collider but thought oh well. Pretty cool to see you be a first tester of sorts for this newer function haha. If you get it working please come back to this post and share, I’m curious.
No because you cannot “check” an effector. Effectors work by performing a modification on an active contact i.e modifying the contact, disabling it etc which is then handled by the solver.
There’s no linkage between an effector and a physics query without giving each physics query or feature knowledge of how effectors work. It’s like implicitly wanting a raycast to pass through a platform effector bearing in mind that this is only one effector type. They are simply not related.
Whilst I can see the utility of Slide + PlatformEffector2D, I also think I’d rather not bind them together. I’d rather consider some other mechanism.