So I have a cart in my game that the player is able to push just by running into and moving it. And also the player is able to grab it and move it using a fixed joint. when the player just pushes the object forward and then jumps on top of it the cart stops immediately regardless of how I set the linear drag, mass, or gravity to either game object. I would like for the player to be able to jump on top of the cart without it losing it’s momentum, or at least not all of it’s momentum immediately upon collision. A little bit of slow down would not be the worst. I need the colliders to still work though so the player can actually stand on top of the cart so the IgnoreCollisions function doesn’t seem to be a good fit. This really seems like it should be an easy fix, but I have been at it for hours with zero success. I read tons of threads in the forum here and on reddit before I made this post and nothing seems to solve my problem. If anyone has any advice it would be very appreciated.
After you leap on the box are you connecting the player to the box with a fixed joint?
And if so, are you continuing to let the player controls dictate the speed of the player? If so, the player controls would stop the player, and thus the attached box.
No I shouldn’t have even mentioned the fixed joint. It only applies with a button press. So it should not be affecting the cart at all when I top. I also have the code where the fixed joint cannot occur when the player on top and have confirmed that isn’t the issue by looking at the cart components in the scene view while playing the game.
Well, here was my 5-minute attempt… seems to work so perhaps it might be useful to you?
No joints, just riding on friction.
7555153–934219–HopOnKurt.unitypackage (6.33 KB)
Actually just messed with it some more, made an antiskid collider on top, a slippery collider on bottom, now you can stand on the box far easier… BUT! You can also control the box by controlling yourself while standing on the Antiskid collider.
If you don’t want to be able to control the box, maybe disable left/right controls when in contact with certain colliders and then made “pushable” colliders at each side of the box that DIDN’T disable those left/right controls, that might get you what you want.
7555165–934222–HopOnKurt2.unitypackage (6.48 KB)
HOLY MOLY! Can’t believe you took the time to make that! Thank you so much! Running in the editor right now and trying to reverse engineer it. I will post back here with the results.
Ok awesome! This got me a lot closer to where I was aiming. I downloaded and implemented ideas from both of your packages. For some reason when I set friction to zero on the cart it never loses it’s velocity and just goes indefinitely which is definitely not what I wanted. I don’t know why the object in your scene does lose it’s velocity eventually. I appear to have it set up the same. Maybe it’s a unity 2d versus 3d thing? So I just have the physics material changing via code when the player is on or off of the cart. That led me to the issue of the cart sliding underneath the player and having the player have to run to keep up with it. So I added a friction to the player on collision and took it off when he leaves the platform. In the past I’ve parented the player to moving platforms and he sticks to that and moves with it perfectly and can also move independently while on the platform. That is ideally what I want but I can’t get the parenting to work because apparently it doesn’t work that way when both objects have rigidbodies. So now when I am on the cart it is moving with the player which is definitely not what I was going for but has kind of led to some fun gameplay anyways. I’ll upload a gif here shortly if it allows me to. Thanks again for taking the time to help me!