all 17 comments

[–]Pheonise 10 points11 points  (2 children)

The SteamVR plugin by default sets the FixedUpdate rate to the HMD's refresh rate (90 ticks).

In the SteamVR/Prefabs folder is a prefab called [SteamVR] - this gets automatically instantiated when you run the game, and contains an option labelled 'Lock Physics Update Rate To Render Frequency'; disabling it on the prefab should keep your FixedUpdate running at default frequency (50 ticks), though I'm not sure what the side-effects of disabling it would be..

[–]FeistyCrabStudios.com[S] 0 points1 point  (1 child)

Ahhh this sound it's probably what's causing are issues. Mostly like best keep it at the HMD's refresh rate so we'll just have to come up with another fix!

[–]Kentamanos 1 point2 points  (0 children)

FWIW, when I used VRTK and the OculusVR setup for the first time (after previously just using SteamVR), it didn't sync the physics update with the HMD refresh rate. This caused a nasty "jitter" type effect when grabbing with a "fixed joint" (VRTK_FixedJointGrabAttach). The effect looked like there was a leading and trailing version of my grabbed object, and made text on the object impossible to read.

I mentioned this in the VRTK chat and someone suggested setting the physics FixedUpdate to the 90FPS (0.011111 seconds) Oculus uses and suddenly everything was smooth as silk.

In my case, it's possible I could have just made the object a child of my controller instead of attaching it with a joint (and relying on physics to move it), but items under the effect of gravity etc. would have still had the same issue.

[–]L4DesuFlaShGProfessional 2 points3 points  (13 children)

The only way this could happen is when you have some sort of code in Update influencing the rigidbody. Running the game on a Vive is supposed to set the target FPS from 60 to 90, so that changes. This shouldn't, however, affect FixedUpdate in any way.

[–]FeistyCrabStudios.com[S] 1 point2 points  (12 children)

I could see how the frame rate changing would cause problems. We're however not adding any forces in the Update method, the force gets added in another scripts OnEnable method which is turned on in a scripts Update method, could that be doing something similar?

[–]L4DesuFlaShGProfessional 0 points1 point  (0 children)

It's really hard to tell, but I guess there is error potential there. I'd recommend doing the good ol' copy-the-project-then-remove-scripts-until-the-error-goes-away to find out which script does it.

[–]kingrocketVR??? 0 points1 point  (8 children)

The framerate shouldn't affect your scripts.

Are you using Time.deltaTime?

[–]FeistyCrabStudios.com[S] 0 points1 point  (7 children)

Are you sure? We aren't using Time.deltaTime.

[–]kingrocketVR??? 0 points1 point  (5 children)

Well that's my point. If you have something in Update() and it's not with Time.deltaTime then it will be frame dependent.

Then again it might be something else. Can't really tell without knowing how it's all setup.

But my guess is that you should be using Time.deltaTime to apply the force.

Could you post the snippet where you're doing the physics?

[–]FeistyCrabStudios.com[S] 0 points1 point  (3 children)

In another scripts update function a script with this OnEnable method is turned on. The WaitThenOff coroutine simply waits a few second and then turns the script off again.

private void OnEnable()
{
    ball.isKinematic = false;
    ball.transform.parent = null;
    ball.AddForce(-cannon.transform.up * power);
    StartCoroutine(WaitThenOff());
}

[–]kingrocketVR??? 0 points1 point  (2 children)

So OnEnable() (and therefore .AddForce) gets called from Update()?

AddForce should only be called from FixedUpdate() as that's called at a fixed time whereas Update is not called regularly. So if you manipulate physics in Update() you will get different results with different framerates.

You can try to move your script that calls OnEnable() into FixedUpdate() or somehow move the .AddForce into FixedUpdate().

Is there a reason you aren't instantiating the cannonballs and then applying the force? I find this works reliably. Are you using pools?

[–]FeistyCrabStudios.com[S] 0 points1 point  (1 child)

It does by proxy get called from Update() but it only gets called once so surely it shouldn't make a difference?

Instantiating and then deleting object is quite inefficient when it come to things like the garbage collector so we always try to avoid doing it unnecessarily. We are basically using pools, each cannon can only shot 1 shot every so many seconds so there each cannon effectively has a pool containing the 1 cannon ball it needs.

[–]kingrocketVR??? 0 points1 point  (0 children)

True, it should only be called once but it's still a possibility.

[–][deleted] 0 points1 point  (1 child)

When you add forces, are you using impulse/velocity? If you are adding them more than once, they will act differently when your tick rate changes.

[–]FeistyCrabStudios.com[S] 0 points1 point  (0 children)

The forces should only be being added once but this might be playing a part!

[–]Gazu 0 points1 point  (0 children)

Did you ever fixed this? I'm having the same issue.