This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello! I have been working on this little project for sometime. I'm very slow on it. I am having problems with movement.

    extends KinematicBody2D

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.

in Engine by (12 points)

1 Answer

0 votes

I'm really lookin for someone to point me to the right direction

Lol saw what you did there :)

The right direction

if your goal is a Hotline Miami style then you're on the right path code wise and for mouse rotations(anti / clockwise) you can always do a distance check. Going to stop typing now since you did not want a straight answer.

by (6,942 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.