+1 vote

As far as I know:

  • I need to use the _integrate_forces() method to rotate a RigidBody without jittering

  • I need to use the _input() method and cast to InputEventMouseMotion to get mouse movement.

So, how can I do both of these things at once? I tried having _input place the rotation amounts in a temporary variable which is later accessed and reset by _integrate_forces(), but that results in laggy mouse movement.

in Engine by (109 points)

Does your whole game lag or just the mouse?
If the whole games lag, maybe only read the mouse every 1/60 of a second or 1/30.

It's just the mouse. I also have the arrow keys set up as rotation and it's smooth as butter.

1 Answer

+2 votes
Best answer

Alright, so I was able to figure it out. You do indeed have to use both methods, and transfer information between them using a temporary variable (such as Vector2).

public override void _Input(InputEvent inputEvent)
    InputEventMouseMotion motion = inputEvent as InputEventMouseMotion;
    if (motion != null) {
        mouseSpeed.y += motion.Relative.y;
        mouseSpeed.x += motion.Relative.x;

private Vector2 mouseSpeed;
public override void _IntegrateForces(PhysicsDirectBodyState state)
    Vector3 angularVelocity = Vector3.Zero;      
    Transform transform = GetTransform();

    angularVelocity -= mouseSpeed.x * 0.125f * transform.basis.y;
    angularVelocity -= mouseSpeed.y * 0.125f * transform.basis.x;
    mouseSpeed = Vector2.Zero;

    state.AngularVelocity = angularVelocity;

This code is designed for RigidBody nodes in any orientation.

Also, ensure that the "Can Sleep" property of the RigidBody node is Disabled, otherwise the _IntegrateForces() method will not be called!

selected by

Bro!! I had a similar problem, I tryed to convert your code to gdscript but i had lot of errors ..could you please rewrite the code in gdsciprt!?

Thanks in advance

Can we make it in GDscript? Thanks

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 Frequently asked questions and 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 [email protected] with your username.