Hello,
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
https://docs.godotengine.org/en/3.0/tutorials/physics/physics_introduction.html#using-rigidbody2d
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))
else:
set_applied_force(Vector2())
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)