0 votes

Hello, I'm a beginner in godot.
I just tried the Navigation Polygon demo project.
Since I prefer c #, convert navigation.gd to NavigationMap.cs.
Everything works fine, but the character movement speed is abnormally fast and no speed value is applied.
what am i wrong?

source code is below.

using Godot;
using System;

public class NavigationMap : Navigation2D
{
    [Export]
    public float speed = 400.0f;
    public Sprite player;

    private Vector2[] path = null;
    private int pathIdx = 0;

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        GD.Print("NavigationMap is ready.");
        player = GetNode<Sprite>("Character");
        SetProcess(false);
    }

    public override void _Input(InputEvent @event)
    {
        if (@event.IsActionPressed("click") == false)
            return;

        GD.Print("NavigationMap is click.");

        UpdateNavigationPath(GetLocalMousePosition());
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        MoveAlongPath(speed * delta);
    }

    public void UpdateNavigationPath(Vector2 destination)
    {
        path = GetSimplePath(player.GetPosition(), destination, true);
        pathIdx = 0;
        SetProcess(true);
    }

    public void MoveAlongPath(float distance)
    {
        // set start position.
        var lastPoint = path[pathIdx];

        // start 1 index because 0 index is current position.
        pathIdx++;

        while (pathIdx < path.Length)
        {
            var distanceBetweenPoint = lastPoint.DistanceTo(path[pathIdx]);

            if (distance <= distanceBetweenPoint)
            {
                player.SetPosition(lastPoint.LinearInterpolate(path[pathIdx], distance / distanceBetweenPoint));
                return;
            }
            else
            {
                lastPoint = path[pathIdx];
                pathIdx++;
                distance -= distanceBetweenPoint;
            }
        }

        player.SetPosition(lastPoint);
        SetProcess(false);
    }
}
in Engine by (17 points)

1 Answer

0 votes

Maybe reduce the speed from 400 to 200/100 and see if still running like sonic

by (170 points)

yes, I'm asking because changing the speed value doesn't change the movement speed.

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.