- Home /
Simple 2D smooth ball movement
I am working on a very simple, but tricky thing:
I want to move a ball across the screen in a smooth way (in 2D space).
Unfortunately whatever approach I make, I always experience jitter. I am currently evaluating it with the editor Gameview running constantly at 60fps.
Aproach #1)
Apply a Rigidbody to the ball Mass 0.01
Drag 0
Angular Drag 0
Gravity off
Interpolate Interpolate
Collision Detection Continous
Contraints:
Freeze Position Z
Freeze Rotation X,Y,Z
Starting Movement with:
rigidbody.AddRelativeForce(new Vector3(0, 30, 0));
Does not look very bad, but its not a smooth animation
Approach #2)
Without rigidbody
Vector3 velocity = new Vector3 (0,30,0);
void FixedUpdate()
{ Vector3 velocityComponent = velocity * Time.fixedDeltaTime; transform.position = transform.position + velocityComponent; }
still no good results
For the record -- when you experience Jitter, very often it has something to do with the fact that you're using Update rather than FixedUpdate (or vice versa) in the wrong situation. You should also be careful about what your camera is doing, if it's not just fixed.
Thx for the note. I had also tried the Update() function with Time.deltaTime and could not see a difference.
The camera is fixed in my setup.
Answer by Berenger · Jan 13, 2012 at 01:56 AM
Take a look at Vector3.SmoothDamp. And if you really need a rigidbody, you should toggle Kinematic in rigidbodies' parameters.