#Rigidbody snagged in mid-air

1 messages · Page 1 of 1 (latest)

unique basin
#

Maybe it's because I'm not quite sure how rigidbody velocity (gravity in specific) works as well as it should, but I have a rigidbody with a script meant to only push it forward while preserving its y velocity (rb.velocity = new Vector3(0, rb.velocity.y, 1); ) and it just looks like this with gravity not affecting it at all. How would I go about fixing that short of making my own gravity?

prisma phoenix
#

If this happens only when your moving (and gravity applies normally otherwise), you could try adding a physics material with no friction

unique basin
prisma phoenix
#

What kind of problems do you think it may cause you?

unique basin
# prisma phoenix What kind of problems do you think it may cause you?

If I had to guess my biggest worry is that it's going to not allow forces acted upon an object to appropriately dissipate when interacting with an object. For instance a player will just keep sliding backwards if something pushes him back. Or, if a player enacts a force on an object (the whole point of using rigidbodies at all I'm lead to believe), the reaction will cause the player to slide backwards because of Newton's third law

#

Though it's mostly the concern of unforseen consequences of a frictionless world since it's not exactly natural

prisma phoenix
#

I think if you dont absolutely need realistic physics, you could use a frictionless approach until it doesnt work for specific edge cases in your game, I try to build all my systems in a isolated and somewhat generic way (when I can), so they can be put into its own scene to test specific edge cases like some of those concerns, an alternative would be managing gravity and other forces yourself, then you have much more finetune over it, and you can also change physics materials and their values by code, so you can have specific conditions swap or disable or change the values of your material - characters can get complex or relatively "simple" depending on what it needs to do in your game and how accurate to real world physics it needs to simulate

unique basin
#

It's not ideal, but I might try just making my own gravity since the system is better set up for that and I can more easily pinpoint problems with that

prisma phoenix
#

I think setting up your own gravity is fine, many custom character controllers usually have their own systems for that reason of being able to more fine-tune how they want the character to respond to the world, and is probably helpful for things like cutscenes or times you need to change how the player works/what they are allowed to respond to, but it can also get complex the more things you need a character to respond to - I think just gravity shouldnt be too complex to control though, and could allow you to do stuff like "zero gravity", buoyancy/swimming, etc

unique basin
#

I'm really just going to have to swallow my pride and make everything frictionless aren't I?

unique basin
#

Nevermind. If I just do a straight forward vector with my own gravity everything works fine. It's only on the controller script I've already made that the snag happens now

unique basin
#

@prisma phoenix I figured out the problem. It's when I increase the movement vector's magnitude that the controller gets snagged. You know why that might be?

#

If I have Vector3.forward as the movement vector and add gravity to it then it doesn't get snagged. But if I have Vector3.forward * 6.5 then it does get snagged shortly before falling down.

brittle bluff
#

[]nocode

proper sinewBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

unique basin
brittle bluff
#

why are people so against posting more of their code lol

unique basin
#

Because it's not relevant. The problem currently is that Vector3.forward + custom gravity works but (Vector3.forward * speedConstant) + custom gravity doesn't

brittle bluff
#

but what's the harm in posting more? that's what i dont get

#

ive lost count of how many times ive heard this argument

unique basin
#

Because there ISN'T more

brittle bluff
#

sometimes its irrelevant, but sometimes it isn't. and we only solved the issue because i nagged on them to just post it

unique basin
#

Not unless you want the custom gravity

#

And that's clearly not the problem or it wouldn't be working with the smaller magnitude either

brittle bluff
#

sigh

unique basin
# brittle bluff sigh
movementVector += Vector3.up * physics.gravity.y * Time.deltaTime * gravityCounter;```

There. Did that tell you anything relevant?
brittle bluff
unique basin
brittle bluff
#

no? i genuinely want to help but i don't understand you resistance to posting more. like i can understand that you feel its irrelevant. heck, i don't even think it will help that much. but logically speaking, more information will help people understand and solve your problem better. that's what i don't get

unique basin
#

No, you don't. You want to nitpick

#

I gave you what you asked for and you're still whining

brittle bluff
#

okay let's assume i want to nitpick. from the way im acting i can understand why you might feel that way. how can i help you right now. ignore what i said before

unique basin
#

Increasing the magnitude of the velocity (minus the gravity) from 1 to 6.5 causes the rigidbody to snag on the block as it's falling down (albeit for a brief period of time) yet it doesn't have this problem when the magnitude is 1. Is this because of the friction? Am I going to have to swallow my pride and just remove friction from the scene entirely?

brittle bluff
#

so it could be clipping into the wall as it falls?

unique basin
#

I know removing friction from the scene causes the problem to disappear, but I'd really rather an alternate solution if possible. Why would the clipping problem disappear if friction is removed? I'm genuinely asking because I'm not super sure how Unity's physics engine handles friction. I ASSUME it dampens velocity if two rigidbodies rub up against each other, but I'm worried removing that will cause a whole slew of problems I can't forsee down the road

brittle bluff
#

does making it frictionless remove the clipping?

#

wait i cannot read

unique basin
#

It keeps it from snagging in midair completely no matter what the rb velocity is, yes

#

But I'm worried that's an insanely destructive solution that will cause many unforseen problems down the road and want to know if there's potentially less destructive ones I can do instead. Custom gravity is the one I'm currently playing with and, while it'll eventually stop being snagged, it still snags for a short period of time before falling to the ground

brittle bluff
#

the force of friction is proportional to the normal force. so if you suddenly ram the object into the wall (by increasing forward velocity), it will experience more friction. that's one possibility for why it snags

#

it does not explain why it might just hover there tho

unique basin
#

The same velocity is continuously being applied to it every update

brittle bluff
#

does it seem predictable or no

unique basin
#

As in this always happens every time I run the game? Yes

#

Currently the code is just set up to apply a simple forward vector at a magnitude of 6.5f and then add gravity to it

brittle bluff
#

is it set up so its basically identical every time? what does the physics material look like

unique basin
#

There is no physics material so I assume that means it's the default one that has 0.6 for all the friction values

#

I have one I made for making everything frictionless, but I would rather not use that unless absolutely necessary

brittle bluff
#

I would make a custom one just to play around with. possibly the friction value is too high?

#

when it snags does it stop completely or just slow down a bit more than usual

unique basin
#

Technically the Y velocity isn't actually zero, but so small it may as well be zero

brittle bluff
#

oh so its falling very very slowly

#

very

#

i would try making a new physics material that has no static friction

unique basin
#

So removing the friction from the scene really is unavoidable then

brittle bluff
#

you'll still have kinetic friction

#

static friction applies when an object is stationary. it prevents an object from starting to move. kinetic friction applies to objects in motion.

#

will there ever be a case where you want friction to stop your object completely?

brittle bluff
#

in that case kinetic friction should still slow your object down enough...?

#

actually no i take that back

unique basin
#

So if I just remove the static friction but leave the kinetic friction intact it should all be fine?

brittle bluff
#

try it. but for example on a ramp you might slowly slide down i think without static friction

unique basin
#

Since, when it's stationary, its y velocity is technically reset to zero

brittle bluff
#

that could cause issues. but its too hard to tell for sure

unique basin
#

If I have custom gravity I can even have it so that it doesn't apply at all if the character is grounded

unique basin
brittle bluff
#

i would play around with it a bit. unfortunately the physics engine might just not behave the way you like it to and there's nothing you can really do to change that