The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

hi, so I've been following this tutorial on youtube that shows how to make Pacman in the Godot Game Engine, and in 17:25 movement seems perfectly running but for me Pacman is stuck at spawn.
link for vid:

   extends Area2D

var direction = Vector2(0,0)
var SPEED = 10
onready var walls = get_parent().get_node("walls")

func _ready():
    position = walls.get_player_init_pos()

func _process(delta):
    if Input.is_action_pressed("ui_up"):
        direction = Vector2(0, -1)
        rotation = deg2rad(-90)
    elif Input.is_action_pressed("ui_down"):
        direction = Vector2(0,1)
        rotation = deg2rad(90)
    elif Input.is_action_pressed("ui_left"):
        direction = Vector2(-1,0)
        rotation = deg2rad(180)
    elif Input.is_action_pressed("ui_right"):
        direction = Vector2(1,0)
        rotation = deg2rad(0)

    var pos_to_move = walls.is_tile_vacant(position, direction)
    if(direction != Vector2(0,0)):
        position = position.linear_interpolate(pos_to_move, SPEED * delta)
# position = walls.is_tile_vacant(position, direction)

extends TileMap

onready var half_cell_size = get_cell_size()/2

func _ready():

func get_player_init_pos():
    var pos = map_to_world(Vector2(14,23))
    pos.y += half_cell_size.y
    return pos

func is_tile_vacant(pos, direction):
    var curr_tile = world_to_map(pos)
    var next_tile = get_cellv(curr_tile + direction)
    var next_tile_pos = Vector2()
    if(next_tile == 15 or next_tile == 16 or next_tile == 17):
        next_tile_pos = map_to_world(curr_tile + direction) + half_cell_size
        next_tile_pos = pos
    return next_tile_pos

ps: those 3 tiles he selected are called for me 15, 16, 17
all help is appreciated ^-^

Godot version Godot Engine v3.3.4.stable.official.faf3f883d
in Engine by (23 points)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.