#Slippery physic material causing issues
1 messages Β· Page 1 of 1 (latest)
as you can see here i have a slippery material (0 dynamic and static friction, as well as minimum friction combine) on the ramp's collider
if you collide with it and continue to add forward force then the player not only moves to the side but also for some reason moves upwards π€
it would be fine if it was going to the side but i dont understand why its going up
my player is set up like this:
head - sphere collider
body - box collider
arms and legs - capsule colliders
the player also has a rigidbody on it, and the movement is physics based
OK, so... imagine you have a ramp and drive a car at it, the car goes up the ramp and you can do a Dukes of Hazard stunt jump, right?
You're asking what makes the car go upwards when it was only driving horizontally?
Or am I misunderstanding the question?
well of course this would be happening because the ramp is at an angle
right
?
but in the video i am approaching the ramp from the side, so it should act like a wall instead of a ramp
You'd think so.
It's likely one of two things...
It's a simulation, so not perfect. Or sometimes too perfect.
So floating point errors or the like could be pushing it slightly.
Then, depending on the physics settings, you get unrealistic behaviour.
ah
have to mess around with some numbers then im guessing π€
The other likely culprit is your character controller.
They often have code to do things like lift you upwards if you're slightly too low. For steps or ramps or stuff.
i do not have a character controller on my player
only my own movement code
and rigidbody
not fully my own code ofc, mainly from a tutorial
With no friction on the wall, and your sideways movement keeping you pressed against it, you might be "sliding" upwards from the character controller pushes.
if i increase the mass of the rigidbody maybe that could fix it?
or maybe increase gravity
What stops you falling through the ground? Just colliders?
yeah
NO! Set it to 9.8 and never touch it!
Unless your game actually has changing gravity, like in a space station.
Because everything you can do by changing gravity, you can do by changing other settings.
If you change one, it effects everything.
Ah, that's more OK, but I'd still avoid it unless you want to tweak physics.
hmm
Change the mass.
You can get great effects by playing with gravity for things like double jump or air hang time.
Like if you have a ground smash attack, you could increase gravity for the fall to make it feel more powerful.
increased mass to 10 and my player couldnt move, then i multiplied the speed by 10 and it moved fine, but the problem still occurred
mmm
interesting stuff
seems like changing mass doesnt affect it
it irritates me that i have to make the materials slippery, because if i dont then my player gets stuck to the side of the ramp and under the ramp upon collision, and it takes a couple seconds of holding down the "move back key" to get unstuck
OK. So the up is either something else, or caused by the sideways push.
What if you stop pushing, does it keep lifting or start falling?
let me try
What if you put a box/wall that isn't angled, does this happen?
What if you put a tiny friction?
by the way, i shouldve said this earlier, this only happens if i approach the side of the ramp from near the lowest part of it, if i approach it from the "middle of the side" then it doesnt happen
begins to fall down
I'm hammering you with the questions because I don't know what the problem is, but have ideas, trying to narrow it down.
yes this is a good way of figuring out problems
nope
You're using a capsule collider, right?
This makes me think it's hitting the curved bottom and getting that upwards push.
thats what i was thinking too
but if i make it a cube collider then the player doesnt deal with ramps very well
Yeah, and that's why it's not happening on the wall.
hm
I have a different, personal solution.
But we can try to sort it out with the capsule.
So, what mass do you have set?
you can put forward the personal solution too if you think it is better π€
1
Let's try to put in realistic values.
This is a character, right? So use maybe 80 or 100?
Yep
thats done
If we keep the physics values approximately realistic, you can "guess" values by googling.
mhm
Let's also set some friction for your material. Unless you literally need it frictionless.
gravity is at -9.81 btw
nono friction is fine
i have it at 0 currently with minimum friction combine
I don't know what real values are, so google. I'm on my phone.
Sounds good. So let's use that range. Slippery surfaces might go lower, but we have a ballpark.
How's it looking now?
Same problem? Has the movement or timing changed?
its currently at 7m/s
let me test it rq
well the movement and timing is fine, and the sliding upwards problem is gone
No, but bear in mind the results will match the value.
So a fast player will launch themselves off the top of a staircase as if it's a stunt ramp.
however this caused the problem that i said earlier
that when my player goes underneath the ramp, it basically gets stuck
but i think i know why this is happening
my idle animation and running animation cause the head to move up and down a bit, so when i go under the ramp maybe the head is still trying to move which is causing issues with the colliders
ill try and see how it works without animations
Yeah, that's "normal" physics, objects get jammed.
We can fix it separately.
Are your colliders on the character head?
If you're using a capsule, there's no head, right?
ah, so whats happening is that when i am stuck under the ramp, if i try to move back out, i can do it easily, however if i try to move back and sideways at the same time, then it starts to move very slowly
sphere collider on the head
capsules on arms and legs
and cube for body
without animations by the way
Why? & are you using physics layers?
let me do a bit of testing one sec
no im not using physics layers
and i thought a sphere collider would help in a situation like this π
yeah the animation is defo part of the problem
well ill be honest i dont even know what those are, so no i dont believe i am using those
OK, so in general the way we'd normally do this is:
Character control just uses a capsule for collision. Ignore the character and animations. Keeps things faster and more predictable for movement.
Then the character has colliders on it, which we use for shooting, animations where it hits things, particle effects etc.
We use physics layers so the capsule ignores the body colliders, and the body colliders ignore the capsule.
ohhh
so theres one big general capsule collider for movement, and then smaller ones for the more specific things
?
Sometimes you don't even need the body colliders.
and the physics layers are so that the capsulecollider doesnt interact with the smaller ones?
interesting
Yes
i will try that now, and let you know how it works
And so we can tell code which colliders we care about
Imagine shooting your character. It's going to hit the capsule before it hits the characters head, right?
If they're on the same layer, what's the point of having that head collider?
yes true
but tbf you can use the head collider for things like headshots
oh wait
i misunderstood the question
mb
Yes, but only if it's in a different location to the capsule. If it's "inside" the capsule we wouldn't get the head shot because we'd hit the capsule shell.
which is why we use layers, as you explained π
Yeah
adding a capsule collider to my player object causes the location of the toolhandle to change π€
nvm
If you wanted to keep it simple, you could make the capsule shorter and put a sphere above it for head shots.
If the exact accurate colliders aren't needed.
good idea
But for a game like fortnight you'll need colliders on the body that move with the animation.
oh
i am making a game like pixel gun 3d, not sure if youve heard of it
basically minecraft with guns and no building
so i guess i do need colliders which move with the body
So with the body colliders turned off, you don't get stuck?
hold on im nearly done π
I haven't
should i keep the animations on or off?
ok, so when i go underneath the ramp, and then move backwards, i can move out
if i continue to apply a forward force as well as a sideways force, i move to the side VERY slowly
howver thats not too much of a problem tbh
That's normal. You're pushing against the wall.
yep
Same thing happens in real life if you try to walk through a wall π
so if i am running into a wall and trying to move sideways at the same time is it possible to make it so that it moves to the side?
LOL
true
actually wait
Yes
ive noticed this mechanic is not actually present in any games
so its fine
in fortnite for example if you are running into a wall and try to move sideways it wont go fast
i think my problems are fixed then
Exactly
thanks a lot
But yes, you can give a little sideways push. Or you can stop the pushing in the wall direction.
mhm
That's useful when players clip the wall when going through doors.
can i ask one more question
ah
Just nudge them, and they think it was their own skill.
π€£
But that's just polish. It's layered on top of the game, not something you need.
Yeah
So, I don't suggest this, because I don't know anyone else who does it. So it'll be hard to find tutorials and other problem solving help...
But what I sometimes do is make a floating sphere for the player.
It detects the ground distance and pushes upwards, but there's no colliders touching the ground.
Then I totally sidestep (ha!) all problems with getting stuck on ground rubble, stairs, the corner of ramps...
oooo
And the upward force can be like a spring. The closer to the ground you are the stronger it pushes.
So it gives this natural bounce.
smart
Jump down and you lower to the ground then bounce back upwards. Sometimes with a little jump.
Run up stairs and you keep going up for a moment, with that feeling of momentum.
so it makes it all feel really realistic
You do have to use IK to place the model feet, because you can't use the character position to know where the ground is.
inverse kinematics
ive heard that before, not sure what it is yet
will have to look into it
I'd say "dynamic" - it's not necessarily realistic.
It depends on what feel you want.
for ground check i just use a raycast from the center of the character pointing down with a length of half the characters height + 0.2f
mm
Check out spherecast.
Same idea, but it's a "fatter" ray.
Otherwise if you walk over a small gap, the ray might think you're falling.
Good luck. You're in for a lot of fun π
the body colliders and the large capsule ("movement collider") should no longer interact, correct?
this is my first time using physics layers
thanks for the help π
My pleasure
You can probably disable the body colliders from interacting with everything.
Since you're not using them to push or to be pushed by anything.
oh yeah i didnt think about that
they will only interact with bullets
Otherwise the body can still get stuck with the ramp etc.
π
If you're interested, here's what the floating ball movement looks like π