Hello! I have been working on this little project for sometime. I'm very slow on it. I am having problems with movement.
onready var sprite = $Sprite
export var max_speed := 500
var direction := Vector2.ZERO
export var drag_factor := 0.5
var desired_velocity := Vector2.ZERO
var steering_vector := Vector2.ZERO
var velocity := Vector2.ZERO
func get_input(delta) -> void:
direction = Vector2(Input.is_action_pressed("move_up"), Input.is_action_pressed("move_right")).rotated(rotation) - Vector2(Input.is_action_pressed("move_down"), Input.is_action_pressed("move_left")).rotated(rotation)
desired_velocity = direction * max_speed
steering_vector = desired_velocity - velocity
velocity += steering_vector * drag_factor * delta
velocity = move_and_slide(velocity)
func _physics_process(delta: float) -> void:
My problem I am having is two things.
I can't seem to get the rotation to match the direction. So if I press left key I always want it to go left. the problem is that is always rotate clockwise and will not rotate counter clockwise when the mouse is below it. I tried other methods but it didn't work.
The last thing is when my KinematicBody2D gets right up to the mouse it just keeps rotating and moving and I am not sure how to fix that.
I'm not asking for a straight answer I'm really lookin for someone to point me to the right direction on how to fix it. but if my code is too rigid please let me know how to fix that.