Physics time on iMac vs iOS device

Probably a very simple solution to this, but posting this now as I look for it:

Spend time converting my little 2D game to using rigidbodies/colliders for everything. Spent time getting all the movement impulses to feel right on the pc.

When I ran it on the iPhone everything moved at quarter speed, or something.

I’m moving the character left/right via code like this:

if (transform.position.x > leftWall) rigidbody.AddForce(-375,0,0);

Changing the code to use our old buddy deltaTime worked, but the code looks like this (to get similar results):

if (transform.position.x > leftWall) rigidbody.AddForce(-65000 * Time.deltaTime,0,0);

It worked on the iPhone but seems silly to use numbers like that.

Thoughts?

  1. don’t use deltatime
  2. put all physics in fixedupdate, not update (see docs, it clarifies this).

Thanks. I just changed Update() to FixedUpdate() and I assume that’s ok? The Update loop was maybe 100 lines long but had 2-3 lines dealing with a rigidbody.

update is called every frame
fixed update is called every tenth of a second i think. (not sure on the interval, but i know its called based on time)

FixedUpdate is looped as often as you want it to be, and unity will render after an Update()

Ideally just physics and maybe sound if its spawned off rigid bodies.

The physics timestep is set in your Edit → Project Settings → Time → Fixed Timestep

Performing actions on physics objects (rigidbody, etc) outside of a FixedUpdate will cause physics sync issues (and thus things behave bizarre) :slight_smile: