+1 vote

Hi all.

So I've got a scene where there are a handful of tanks, an obstacle, and a TileMap.
The tanks only move when they are individually selected, and given a destination.
What I want is for them to, when their destination doesn't have anything else in it, move to the center of the tile at that (global) position. Otherwise, if they bump into another tank, or the obstacle, they go back to the previous empty tile.

The tiles for my TileMap are hexagons 256 pixels wide, and 223 pixels tall. Obstacles are centered on their tiles, and I want the tanks to be centered when they aren't moving.

in Engine by (197 points)

1 Answer

0 votes

This question seems a bit brought, this video might give you an idea what you can do:
In the second part there is grid-based pathfinding with collision avoidance.
https://www.youtube.com/watch?v=Ad6Us73smNs&t=

by (51 points)

I am using this grid as well and I think it has to be noted that, due to the way the movement is calculated, the path gets "smoothed out". The arrival to a point in the path is validated by the distance of the entity to the point. Therefore the entity never really "arrives" at the point.

To achieve a more grid-like movement, you should decrease the MASS and ARRIVE_DISTANCE properties. I found that the following settings work well for me:

var MASS = 1.0
var ARRIVE_DISTANCE = 5.0

To "snap" the entity's position to the grid, you could set the position after the entity arrives at the final point:

func _process(delta):
if not _state == STATES.FOLLOW:
    return
var arrived_to_next_point = move_to(target_point_world)
if arrived_to_next_point:
    # Remember next_point before removing it
    var next_point = path[0]
    path.remove(0)
    if len(path) == 0:
        # Set position to point in path
        position = next_point
        _change_state(STATES.IDLE)
        return
    target_point_world = path[0]
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.