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!