So I'm making a RigidBody2D player and when it rotates with an applied_torque, I want that torque/rotation to snap each 8 degrees...I have written some code below of what I currently have:

extends RigidBody2D

var speed = 300
var turn_angle = 250
var rotation_dir = 0
var spin_thrust_dir = 300
var angle = 0
var move_direction = Vector2()

func _process(delta):
	if Input.is_action_pressed("move"):
		move_direction = Vector2(speed, 0)
	elif Input.is_action_pressed("backwards"):
		move_direction = Vector2(-speed / 1.5, 0)
	else:
		move_direction = Vector2(0, 0)
	rotation_dir = 0
	if Input.is_action_pressed("right"):
		move_direction = Vector2(turn_angle, 0)
		rotation_dir += 1
	if Input.is_action_pressed("left"):
		move_direction = Vector2(turn_angle, 0)
		rotation_dir -= 1

func _integrate_forces(state)):
	var a = position.direction_to(#nothing yet#).angle()
	rotation = stepify(a, PI/4)
	set_applied_torque(rotation_dir * spin_thrust_dir)
	set_applied_force(move_direction.rotated(rotation))

Any code examples to fix my code (the first 2 lines in physics process, it doesn't work)?

Thanks!

DaveTheCoder Ok thank you, did that but the code still doesn't work... I need to change something about this:

	var a = position.direction_to(#nothing yet#).angle()
	rotation = stepify(a, PI/4)

    DaveTheCoder
    This is the _integrate_forces code:

    func _integrate_forces(state):
    	angular_velocity = stepify(rotation, PI/16)
    	set_applied_torque(spin_thrust_dir * rotation_dir)
    	set_applied_force(move_direction.rotated(rotation))
    
    	if abs(get_linear_velocity().x) > terminal_velocity:
    		var terminal = linear_velocity.normalized()
    		terminal *= terminal_velocity
    		set_linear_velocity(terminal)

    the result:
    The player can't even rotate anymore.