0 votes

I made everything exactly like in the video(https://www.youtube.com/watch?v=DjR4nKlyY4I&list=PLf0k8CBUad-v_J1Xq5XW7FEUHokxSuYnF&index=18&t=0s), but new Godot every time sends me an error:
Invalid call. Nonexistent function "distance_to" in base Vector2
rec://big.gd - 25
What did I make wrong?
I need the answer as soon as it possible
Please:

extends Sprite

const RADIUS = 75
const SMALL_RADIUS = 35

var stick_pos
var evt_index = -1

func _input(event):
    if event is InputEventScreenTouch:
        if event.is_pressed():          
            position = event.position
            stick_pos = position
            $small.position = Vector2()
            if stick_pos.distance_to(event.position) < RADIUS:
                evt_index = event.index
        elif evt_index != -1:
            if evt_index == event.index:
                evt_index = -1
                $"../".stick_speed = 0
                $"../".stick_vector = Vector2()
                $"../".stick_angle = 0

    if evt_index != -1 && event is InputEventScreenDrag:
        var dist = stick_pos.distanse_to(event.position)#here is the problem
        var vect = (event.position - stick_pos).normalized()
        if dist+SMALL_RADIUS > RADIUS: dist = RADIUS-SMALL_RADIUS

        $"../".stick_speed = dist
        $"../".stick_vector = vect
        $"../".stick_angle = event.position.angle_to_point(stick_pos)


        $small.position = vect
in Engine by (14 points)
edited by

Why does my joystick work, but DOESN'T MOVE?

1 Answer

0 votes

You made a typo:

    var dist = stick_pos.distanse_to(event.position)#here is the problem

It's distance_to, not distanse_to

by (27,660 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 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 webmaster@godotengine.org with your username.