character movement is too fast. please help me. (c#)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AuraBunny

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);
    }
}
:bust_in_silhouette: Reply From: DarlesLSF

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

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

AuraBunny | 2019-12-04 17:04