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?
#Rigidbody snagged in mid-air
1 messages · Page 1 of 1 (latest)
If this happens only when your moving (and gravity applies normally otherwise), you could try adding a physics material with no friction
Yeah, that's the solution that ended up working, but I'm worried that this might cause problems later down the line
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
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
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
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
It's still having a bit of the snag issue albeit for a short period of time before working properly again when trying to implement my own gravity
I'm really just going to have to swallow my pride and make everything frictionless aren't I?
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
@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.
[]nocode
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
The code is literally one line and I posted it
why are people so against posting more of their code lol
Because it's not relevant. The problem currently is that Vector3.forward + custom gravity works but (Vector3.forward * speedConstant) + custom gravity doesn't
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
Because there ISN'T more
sometimes its irrelevant, but sometimes it isn't. and we only solved the issue because i nagged on them to just post it
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
sigh
movementVector += Vector3.up * physics.gravity.y * Time.deltaTime * gravityCounter;```
There. Did that tell you anything relevant?
okay wait answer this question
I just did. It didn't tell you anything relevant meaning I was right and it's irrelevant and you're being needlessly nitpicky
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
No, you don't. You want to nitpick
I gave you what you asked for and you're still whining
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
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?
so it could be clipping into the wall as it falls?
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
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
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
The same velocity is continuously being applied to it every update
does it seem predictable or no
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
is it set up so its basically identical every time? what does the physics material look like
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
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
Technically the Y velocity isn't actually zero, but so small it may as well be zero
oh so its falling very very slowly
very
i would try making a new physics material that has no static friction
So removing the friction from the scene really is unavoidable then
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?
Yes
Most likely anyway
in that case kinetic friction should still slow your object down enough...?
actually no i take that back
So if I just remove the static friction but leave the kinetic friction intact it should all be fine?
try it. but for example on a ramp you might slowly slide down i think without static friction
Oh that shouldn't be a problem. I'm pretty sure the movement code I have solves that implicitly
Since, when it's stationary, its y velocity is technically reset to zero
that could cause issues. but its too hard to tell for sure
If I have custom gravity I can even have it so that it doesn't apply at all if the character is grounded
I think I have an idea of how to solve those problems when it comes to that. The thought is that, in those instances, the ability for the player to freely move should be disabled anyway
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