0 votes


I'm trying to create a character with completely physics-based movement. It's supposed to be able to move along the X and Y axes, as well as rotate. The movement works fine, but I can't get the thing to rotate. Can anyone help me?

I tried to use the code found at
However, even when copy-pasting the code, the movement works fine, but the thing still won't rotate. No error, it just won't do anything when the keys are pressed.
"Can sleep" is turned off.

This is my version of the code (slightly modified but the rotation part is the same):

extends RigidBody2D

var max_speed = 250.0
var thrust = 250
var torque = 20000

func _integrate_forces(state):
    if state.linear_velocity.length()>max_speed:
    state.linear_velocity = state.linear_velocity.normalized()*max_speed

    if Input.is_action_pressed("move_forward"):
        set_applied_force(Vector2(0, -thrust).rotated(rotation))
    elif Input.is_action_pressed("move_backward"):
        set_applied_force(Vector2(0, thrust).rotated(rotation))
    elif Input.is_action_pressed("strafe_left"):
        set_applied_force(Vector2(-thrust, 0).rotated(rotation))
    elif Input.is_action_pressed("strafe_right"):
        set_applied_force(Vector2(thrust, 0).rotated(rotation))         

    var rotation_dir = 0
    if Input.is_action_pressed("rotate_right"):
        rotation_dir += 1
    if Input.is_action_pressed("rotate_left"):
        rotation_dir -= 1
    set_applied_torque(rotation_dir * torque)
Godot version 3.3.3 stable official
in Engine by (31 points)

Not to be patronising, but did you make sure to bind the input actions in the project settings?

Not patronizing, I wondered about that, too. I double-checked the input, it works fine.

I found some articles that said a collision shape or collision polygon is required for setappliedtorque to function. I didn't have that. Added one in now. Still doesn't work.

Edit: I'm using setangularvelocity now. That works. Multiple articles state one should use setappliedtorque, but if that doesn't work, what can I do.
I'd still like to know why setappliedtorque doesn't work, especially since that's the one all the rigidbody tutorials are using, so if anyone knows, please, tell me.

1 Answer

0 votes

Okay, I figured it out. I followed a tutorial and that guy set the Rigidbody2d's Mode to Character. He later changed it back to Rigid but never mentioned it.
Character behaves exactly like Rigid with the exception that IT CANNOT ROTATE.
Well, it can. But not using torque.

by (31 points)
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.