+1 vote

Hi Guys. I'm testing a point-and-click movement mechanics in 3D, which is working fine. I have a move_to function which gets the path between the character's current position and target. The target is assigned in the main script (basically casting a ray from the mouse and capturing the position where collides with the ground). I'm using the move_and_slide method to move the character along the path towards its target position.
Question: how do I ease-in the movement so that the character doesn't abruptly stop when it reaches the target position??

Here is the character script:

var path = []
var path_index = 0
var move_speed = 12
onready var nav = navigation node

func move_to(target_position):
    path = nav.get_simple_path(global_transform.origin, target_position)
    path_ind = 0

func _physics_process(delta):
    if path_index < path.size():
        var move_vec = (path[path_index] - global_transform.origin)
        if move_vec.length() < 0.1:
            path_index += 1
            move_and_slide(move_vec.normalized() * move_speed, Vector3(0, 1, 0))
in Engine by (389 points)

2 Answers

+1 vote

why not simply reducing the move-speed when you're approaching the final target position? You already know the move-vec vector, so from its length you know how far you are from the final position...

by (69 points)

I was thinking about this actually. Eg, if distance between the character and target position is less than something, move_speed -= 1. I'll try this out.

0 votes

You can use the Tween node for this purpose. See this tutorial for a practical example.

by (9,272 points)

I've already tried. Tween works beautifully here but it interpolates between the start and end position only, meaning it ignores the navigation mesh and the character is happily passing through walls etc.

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.