+1 vote

I'm having issues when loading my project in the latest engine alpha. Player movement no longer works in Godot 3.1 alpha 3 and alpha 4, but it worked fine up until alpha 2.

The player is a KinematicBody2D and I'm using moveandcollide(). This is the relevant part of the code, I think:

    if not is_moving and direction != Vector2():
        target_direction = direction.normalized()
        if grid.is_cell_vacant(get_position(), direction):
            target_pos = grid.update_child_pos(get_position(), direction, type)
            is_moving = true
    elif is_moving:
        #print("current room: " + str(get_room()))
        if global.on_episode == false and global.HP > 0: get_worldmap_coordinates()
        speed = MAX_SPEED
        velocity = speed * target_direction * delta

        var pos = get_position()
        var distance_to_target = pos.distance_to(target_pos)
        var move_distance = velocity.length()

        if move_distance > distance_to_target:
            velocity = target_direction * distance_to_target
            is_moving = false


"grid" is a TileMap and the parent of the player.

My player script is a bit complex (and messy at parts, since I'm an amateur) and it depends on other scripts, so the problem might lay elsewhere. This is the complete script, for reference: https://gitlab.com/alforiumstudios/monsterembassy/blob/master/game_source/system/player/player.gd
The project is open-source, so you can even download the entire game and try it out yourself. The player gets stuck and doesn't move.

I've been looking at the engine's change logs, pull requests, etc. but I can't figure out what's changed to suddenly break this. Has there been any important changes in stuff like framerate calculation, collision, etc.? Or perhaps breaking changes in how TileMaps are handled?

I'd really appreciate any help!

asked Dec 28, 2018 in Engine by alforiumstudios (28 points)

You should probably report this as a bug too. Such a breaking change should at least be in a change log, if not corrected.

1 Answer

0 votes
Best answer

Did you add a CollisionShape2D as a child to the KinematicBody2D node?

I've only started using Godot today and couldn't get my sprite moving. I figured out that I need to add a CollisionShape2D, but nobody mentioned this in YouTube tutorials so I assume it's a new thing.

answered Jan 2, 2019 by jsilvano (44 points)
selected Jan 2, 2019 by alforiumstudios

Thank you thank you thank you! That was exactly it! I use a tilemap grid for movement, so none of my kinematicbody2d nodes had collision shapes assigned to them. Thanks so much :)

Nice one. I bumped into this thread while I was searching for the solution, it's nice to know now I've helped you solve it :)

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.