#Slippery physic material causing issues

1 messages Β· Page 1 of 1 (latest)

gleaming socket
#

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

barren vigil
#

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?

gleaming socket
#

right

#

?

#

but in the video i am approaching the ramp from the side, so it should act like a wall instead of a ramp

barren vigil
#

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.

gleaming socket
#

have to mess around with some numbers then im guessing πŸ€”

barren vigil
#

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.

gleaming socket
#

only my own movement code

#

and rigidbody

#

not fully my own code ofc, mainly from a tutorial

barren vigil
#

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.

gleaming socket
#

or maybe increase gravity

barren vigil
#

What stops you falling through the ground? Just colliders?

gleaming socket
#

yeah

barren vigil
gleaming socket
#

whys that

barren vigil
#

Unless your game actually has changing gravity, like in a space station.

gleaming socket
#

ohh

#

no i meant the gravity of the rigidbody mb πŸ˜…

barren vigil
# gleaming socket whys that

Because everything you can do by changing gravity, you can do by changing other settings.
If you change one, it effects everything.

barren vigil
gleaming socket
#

hmm

barren vigil
#

Change the mass.

gleaming socket
#

ill try that

#

one second

barren vigil
#

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.

gleaming socket
#

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

gleaming socket
#

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

barren vigil
#

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?

barren vigil
#

What if you put a box/wall that isn't angled, does this happen?

#

What if you put a tiny friction?

gleaming socket
#

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

barren vigil
#

I'm hammering you with the questions because I don't know what the problem is, but have ideas, trying to narrow it down.

gleaming socket
barren vigil
gleaming socket
#

but if i make it a cube collider then the player doesnt deal with ramps very well

barren vigil
#

Yeah, and that's why it's not happening on the wall.

gleaming socket
#

hm

barren vigil
#

So, what mass do you have set?

gleaming socket
gleaming socket
barren vigil
#

Let's try to put in realistic values.
This is a character, right? So use maybe 80 or 100?

gleaming socket
#

yeah

#

ill increase the speed and jump force too

barren vigil
#

Yep

gleaming socket
#

thats done

barren vigil
#

If we keep the physics values approximately realistic, you can "guess" values by googling.

gleaming socket
#

mhm

barren vigil
#

Let's also set some friction for your material. Unless you literally need it frictionless.

gleaming socket
#

gravity is at -9.81 btw

gleaming socket
#

i have it at 0 currently with minimum friction combine

barren vigil
#

I don't know what real values are, so google. I'm on my phone.

gleaming socket
#

alright

#

around 0.4-0.6

#

unity had it at 0.6 for default

barren vigil
#

Sounds good. So let's use that range. Slippery surfaces might go lower, but we have a ballpark.

gleaming socket
#

mm

#

does the speed of the player need to be realistic πŸ€”

barren vigil
#

How's it looking now?
Same problem? Has the movement or timing changed?

gleaming socket
#

its currently at 7m/s

gleaming socket
gleaming socket
barren vigil
gleaming socket
#

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

barren vigil
#

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?

gleaming socket
#

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

gleaming socket
#

capsules on arms and legs

#

and cube for body

gleaming socket
barren vigil
#

Why? & are you using physics layers?

gleaming socket
#

let me do a bit of testing one sec

gleaming socket
#

and i thought a sphere collider would help in a situation like this 😭

#

yeah the animation is defo part of the problem

gleaming socket
barren vigil
#

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.

gleaming socket
#

so theres one big general capsule collider for movement, and then smaller ones for the more specific things

#

?

barren vigil
#

Sometimes you don't even need the body colliders.

gleaming socket
#

and the physics layers are so that the capsulecollider doesnt interact with the smaller ones?

#

interesting

barren vigil
#

Yes

gleaming socket
#

i will try that now, and let you know how it works

barren vigil
#

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?

gleaming socket
#

but tbf you can use the head collider for things like headshots

#

oh wait

#

i misunderstood the question

#

mb

barren vigil
#

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.

gleaming socket
#

which is why we use layers, as you explained πŸ‘

barren vigil
#

Yeah

gleaming socket
#

adding a capsule collider to my player object causes the location of the toolhandle to change πŸ€”

#

nvm

barren vigil
#

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.

barren vigil
#

But for a game like fortnight you'll need colliders on the body that move with the animation.

gleaming socket
#

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

barren vigil
#

So with the body colliders turned off, you don't get stuck?

gleaming socket
gleaming socket
#

should i keep the animations on or off?

gleaming socket
#

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

barren vigil
#

That's normal. You're pushing against the wall.

gleaming socket
barren vigil
#

Same thing happens in real life if you try to walk through a wall πŸ˜‰

gleaming socket
#

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?

gleaming socket
#

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

barren vigil
#

Exactly

gleaming socket
#

thanks a lot

barren vigil
#

But yes, you can give a little sideways push. Or you can stop the pushing in the wall direction.

gleaming socket
#

mhm

barren vigil
#

That's useful when players clip the wall when going through doors.

gleaming socket
#

can i ask one more question

barren vigil
#

Just nudge them, and they think it was their own skill.

gleaming socket
#

🀣

barren vigil
#

But that's just polish. It's layered on top of the game, not something you need.

gleaming socket
#

yeah pretty much

#

need to get the basics done

barren vigil
#

Yeah

barren vigil
#

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...

gleaming socket
#

oooo

barren vigil
#

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.

gleaming socket
#

smart

barren vigil
#

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.

gleaming socket
#

so it makes it all feel really realistic

barren vigil
#

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.

gleaming socket
#

inverse kinematics

#

ive heard that before, not sure what it is yet

#

will have to look into it

barren vigil
gleaming socket
barren vigil
#

Otherwise if you walk over a small gap, the ray might think you're falling.

gleaming socket
#

oh yeah true

#

ill look into that

barren vigil
#

Good luck. You're in for a lot of fun πŸ™‚

gleaming socket
#

the body colliders and the large capsule ("movement collider") should no longer interact, correct?

#

this is my first time using physics layers

gleaming socket
barren vigil
#

My pleasure

barren vigil
gleaming socket
#

they will only interact with bullets

barren vigil
#

Otherwise the body can still get stuck with the ramp etc.

gleaming socket
#

πŸ‘Œ

barren vigil
#

If you're interested, here's what the floating ball movement looks like πŸ™‚