**extends CharacterBody2D


var Player

func _ready():
Player = get_node ("/root")

func physics_process(delta):
var direction = global_position.direction_to(Player.global_position)
velocity = direction * 300.0
move_and_slide()** enemy slime code.

When I go play other scenes, the player, game, trees are fine. But when I add the enemy slime code to the game it doesn't work, what do I do?

There are no errors either.

  • Jesusemora replied to this.
  • lukboy

    Player = get_node ("/root")

    what are you doing???

    your scene will be instantiated, that is not your root, your root will be the center of the world, 0 0.
    if your player is the root scene... It's wrong. the root scene should be your level and the player has to exist inside the level.

    or give your player a more descriptive name.

    In order to get your player, use groups.
    the tab next to inspector, node, lets you create a group. you can then access the nodes in the group with:

    get_tree().get_nodes_in_group("player")

    and if you have only one node in this group, the player, you can just access the first element of the array returned, and that will give you the player:

    Player = get_tree().get_nodes_int_group("player")[0]

    lukboy

    Player = get_node ("/root")

    what are you doing???

    your scene will be instantiated, that is not your root, your root will be the center of the world, 0 0.
    if your player is the root scene... It's wrong. the root scene should be your level and the player has to exist inside the level.

    or give your player a more descriptive name.

    In order to get your player, use groups.
    the tab next to inspector, node, lets you create a group. you can then access the nodes in the group with:

    get_tree().get_nodes_in_group("player")

    and if you have only one node in this group, the player, you can just access the first element of the array returned, and that will give you the player:

    Player = get_tree().get_nodes_int_group("player")[0]