0 votes

My original question with some code which I made so far https://godotforums.org/discussion/29532/rotate-sprite-and-move-to-mouse-click-position-2d#latest

I have a sprite, I click somewhere and I want that sprite rotate to mouse click position and move there.

Code which perform correct moving but without rotation:

func set_move_target(target):
    target_pos = target
    angle_to_target = target_pos.angle()

func move_to_target(delta):
    velocity = Vector2(speed, 0).rotated(angle_to_target)
    return move_and_slide(velocity) 

func _process(delta):
        if Input.is_mouse_button_pressed(BUTTON_LEFT):
            set_move_target(get_local_mouse_position())

        if target_pos:
            move_to_target(delta)

If I add property rotation and set its value - eveything becomes chaotic, random moves, rotations, etc.
What's wrong with my calculations and how to use properly godot features?

Godot version 3.4.4
in Engine by (12 points)

Please log in or register to answer this question.

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.