Here’s my layout. I’m making a bowling game. I recently added curve slider UI’s to adjust the ball curve. Along with a power slider. It all works. Except for this. The ball will make a little jump after hitting the friction part of the lane depending on what the curve and power are set to. I have two lane parts. One part has a physics material that gives it no friction. The other part has no physics material or anything. The ball curves when it hits it, but also a small jump aswell. Any reason why? What might be causing this to happen? Here is a gyazo.
Very, very frustrating!
Oh there’s the code I use.
public void Throw_Ball(float curve, float sidespin, float Power)
{
gameObject.GetComponent().AddForce(new Vector3(0,0,Power));
gameObject.GetComponent<Rigidbody().angularVelocity = new Vector3(0,sidespin,curve);
}
Is your mesh two seperate colliders? Try to merge the mesh into one.
Interesting idea. But the thing is, one part has friction so the ball curves with any angularVelocity it has applied to it and the other part has a NoFriction physic material so the ball slides down the lane with any angularVelocity applied.
The physics engine likes to do that when an object moves from one collider to another unfortunately.
There are a few things you can try, decreasing the timestep, increasing the physics iteration count, adjusting the contact offset, and having the rigidbodies use continuous collision.
Tried everything except for contact offset. Nothing works. Why does unity have to do this? I can’t even design a simple bowling game without it bugging out. Any other help?
Laterally thinking, could it be done with a single collider for the whole lane, with no friction material added initially, and then add the friction material when the ball is a certain distance down the lane?
I haven’t tried doing it myself and I don’t know if it will work, but I thought I’d throw the idea out there just in case it helps.
A few ideas come to mind:
-
Have you tried playing with the RigidBody’s collision detection settings? I.e., discrete versus continuous versus continuous dynamic?
-
You might be able to reduce it to the point where it’s not noticeable by decreasing the fixed time step so the physics are computed more frequently. This could make the effects of sudden force spikes less noticeable. In Unity’s menu go to Edit->Project Settings->Time to adjust Fixed Timestep to a smaller number.
-
Increase the PhysicsManager Solver Iteration Count (in Unity’s menu go to Edit->Project Settings->Physics). If that makes it worse, try decreasing it instead.
None of these will make it act perfectly like a rolling ball, but they might reduce the jump to the point where it’s not visible or is at least tolerable. Failing that, it’s not an easy problem to solve. A sudden change from zero or very low friction to higher friction must be causing the vertical component of the force/impulse to exceed the weight of the ball which shoots it upwards. I’m not sure if you can scale the force back down to make sure the vertical component equals the weight of the ball, but that’d be the sure-fire way to keep it from jumping. The trouble is though I think that you can’t jump into the middle of the physics cycle and modify what happens after a collision.
- Is the ball ever supposed to leave the ground under any circumstances once it’s been thrown? If it’s ok for it to never jump or bounce, you might be able to constrain it vertically, or just set the y component of the velocity to 0 every FixedUpdate() and set the y component of the position back to where it should be, at least when it’s in the actual lane and not falling into the gutter or something. That would probably work if your bowling game is flat like a real bowling alley.
The first thing I would try is #1.
Hey thanks for the replies everybody. @ , I have tried all of the listed options to no avail. I also tried using Freeze Y, it worked fine. But I mean if the ball drops in the gutter it will still be floating… That idea with the distance was a pretty darn nice idea. Also, with that being said, I could easily create heavier or lighter oil patterns by simply modifying the distance value. I might actually wanna try that. So like, there would only be 1 lane part with a friction material, and when the ball comes across a certain distance I’ll remove the component. Oh wait I don’t actually know if I know how to remove a physics material lol. If some one could answer that that’d be great. I might try this before I try another idea I had in mind to chop down the velocity to 0 or under if the Y velocity is ever higher than a certain number.
The distance solution worked! Thanks so much everyone.
1 Like