Two meshes appear in game when moving kinematic body as a child node of spatial node

QushyQushy Posts: 6Member

Hello, I have a REALLY weird issue and I don't know what to do. This is the code I use to move the object:

get_node("KinematicBody").move_and_collide(delta * (player.global_transform.origin - get_node("KinematicBody").global_transform.origin))

The scene is set up like this:
Root (Spatial node)

The script is attached to the Root node.

This is the result I'm getting:

I have only one enemy instance in the scene. Can someone explain why this happens and how to avoid it?


  • TwistedTwiglegTwistedTwigleg Posts: 3,557Admin

    I've never had this issue myself, but from what it looks like there appears to be two meshes in the scene. When you run the game and press remote on the scene tree in the Godot editor, does it shows multiple MeshInstance nodes? Maybe something is getting duplicated.

  • cyberealitycybereality Posts: 1,090Moderator

    "move_and_collide" accepts a linear velocity and should not be combined with delta first. Also, is what you are passing a velocity? This line doesn't make sense to me:

    player.global_transform.origin - get_node("KinematicBody").global_transform.origin

    I assume "KinematicBody" is your enemy. So want the enemy to walk toward the player? If so, you can do something like this:

    var enemy = get_node("KinematicBody")
    var dist = player.translation - enemy.translation
    dist = dist.normalized()
    var enemy_walk_speed = 1.0
    enemy.move_and_collide(dist * enemy_walk_speed)

    Note I didn't test the code, just writing from memory, but it should be something like that I think.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file