+1 vote
func _input(event):
if event is InputEventMouseMotion:
    # Rotates the view vertically
    $Head.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
    $Head.rotation_degrees.x = clamp($Head.rotation_degrees.x, -75, 75)

    # Rotates the view horizontally
    self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))

I have this code to look around in 3D but I want it in physicsprocess(delta) because probably _input(event) causes the jitter in my project.

Godot version 3.3.2
in Engine by (55 points)

You don't want this code in _physics_process, 20xxdd20.
Doing this will cause the player to feel lag in their mouse input, which I think is more unacceptable than jitter. In the first place, this is not even possible in _process without convoluted code (which would definitely make the problem far worse).

But I'd be surprised if _input(ev) causes any sort of performance overhead for your project. Even if you do nothing and have no code at all, the engine ensures the following queries always takes place every single frame:

(has something happened? i.e, the mouse moves), then:

 > query the _input(ev) function
 > query the Control nodes
 > query _unhandled_input(ev)
 > finally, query the CollisionObject nodes (3D/2D camera casting)

This happens even with no code. Did you notice?

Especially in Godot, but also as standard practice, it's generally the content of your code that is responsible for the major (lack of) performance, not so much where you are putting it.

From experience, I'm pretty confident you'll find that your jittering issue lies elsewhere.

I experimented with different displays and it seems like the jitter is on higher hz monitors (above 60hz). I tried it on 60hz monitor and no jitter at all. I tried putting physics fps to 75 (my display hz) and the there was no jitter at all. Seems like putting higher physics fps solves the problem. That could be a solution?

This will have no effect whatsoever on the performance (or jitter), however, I am just noting that, in your code, you are multiplying by -1, when you can append a - before the deg2rad(), however, this is just my opinion, not sure what the preferred style is in GDScript, though). Anyway, hope you find the solution to your problem.

Okay, so it sounds like you are having the physics interpolation jitter issue. This is something that is getting worked on engine-level and isn't the fault of your project.

See this YouTube video for a demonstration of what it looks like:
https://youtu.be/lWhHBAcH4sM?t=34

And this is the current solution (from the video), which is an addon that was designed specifically to solve it:
https://github.com/lawnjelly/smoothing-addon

I believe you need to include the files in every project you have the issue in, but the installation process is relatively straightforward, quoting:

  1. Create a new project in Godot or use an existing project.
  2. Copy the 'addons' folder from this repository to your Godot project folder.
  3. Go to 'Project Settings' plugins tab.
  4. Find the smoothing plugin and set status to 'Active'.

Hope it helps!

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.