- Home /
Roll-A-Ball Movement (Without Endless Run) [C#]
So This is The Problem:
When You Use Rigidbody's AddForce function with Input Axes in Update, It works well but runs forever , even if you press nothing ....
When You Use Rigidbody's Velocity Vector3 with Input Axes in Update, it works better ' stops when you press nothing , but seems like gravity is not affecting on ball while it is flying ...
So Maybe You Know How To Make Roll-A-Ball Movement More Realistic ?
Answer by mayur7garg · Jul 16, 2018 at 12:47 PM
Try using AddForce(Vector3 force, ForceMode.Impulse)
Impulse force mode applies only an instant force instead of a continuous force.
Uhh looks like Impulse force mode is moving the ball endless , too.....
Answer by JVene · Jul 16, 2018 at 12:52 PM
@NarekFT, I've been working on a simulation of a real world game, a tournament for high school robotics, where they use, among other objects, a 3 inch plastic ball that weighs 2 ounces. I call it a big ping-pong ball. It bounces forever on a hard floor (in real life...well, not forever, but unusually long for a real object, like ping-pong balls), but the game is played on a mat with a slight cushion. Controlling bounce and roll has been quite a challenge.
To do that I've attached a script to the ball which tracks velocity in FixedUpdate, adjusting drag and bounce depending on context. When the ball strikes various parts of the arena, which are either metal or plastic, I got the bounce about right using rather standard adjustments of the materials, but bouncing and rolling on the mat would never be right. There was always the problem of getting one thing right that makes the mat, and particularly bouncing on the floor and rolling forever, quite wrong (and unending). In order to get the bounce right on hard platforms in the arena, but the mat correct, I could not rely on simply adjusting materials.
I had to adjust settings on the ball based on what it was colliding with, or rolling on, and how fast it was moving in that context. As the ball slows I add drag using a curved graduation to get it to come to rest in likeness to experimental observations made with the real objects in similar context.
PhysX, the engine inside Unity, is fairly good at bouncing, motion - basic Newtonian physics, but the limitations of an impulse based design leaves us with a restitution value that either limits small bounces too much, or suddenly stops a rolling ball that should more gradually come to a stop. When these limits are adjusted, bounces never stop, everything jitters on it's own, and rolling just never ends. There is no global adjustment that just works in all context. For that, one must take over and control these values to counter the limits required by the engine so it doesn't become unstable.
Then, there's bouncing off a net. There's a net backdrop in the arena, about 6 feet high, to stop balls from leaving the arena when fired at targets. Getting that bounce just right was a major tour through kludgey solutions. Ultimately I chose to add an inverse force from the collision to make the ball bounce in a way analogous to video observations taken of the ball reacting with the net in the real example.
I think you can spend weeks or months getting things just right if you're particular. In the case of simulating a real world contest, which isn't as much a game as it is a tool for experimentation for a team evaluating a robot design (in high school clubs), I had to get the behavior right. I called it good enough after about 5 days.
I revisited it for another 20 hours or so again as I observed the release builds on various hardware, with minor adjustments to the script.
I can still see flaws, but they're minor, and the result is effective, and hardly anyone but other game designers would notice what I see. What I'm saying here is that you do have to reach a point where you can call good enough an endpoint.
Yet, at the start, all the defaults are not, generally, good enough. That's not Unity specific, or even PhysX specific where it's used in other engines and games. That's the nature of real time physics engines.
Lol , So There is No Any Simple Way for $$anonymous$$oving The Ball Like Velocity does ?