Problem with PathFollow

BredemarBredemar Posts: 15Member
edited July 12 in 3D

Hello again! I want to make random enemies. On one of lessons (but there 2D, I do in 3D, probably because of it and problems, very few lessons on 3D, it is sad). Added a Path node, drew a curve (two points), tied a PathFollow node. Because of a simple timer I wanted to "summon" enemies, but an error occurs: "Invalid call. Nonexistent function 'position' in base 'PathFollow'."

As I understand it, there is no such parameter, but in the documentation I did not find the parameter I need, so I do not know how to implement it, here is my code:

func _on_Timer_timeout():
    $Path/PathFollow.offset = randi()
    var enemy = Enemy.instance()
    add_child(enemy)
    enemy.position = $Path/PathFollow.position()

Thanks.

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    If you are using 3D, you will need to replace position with transform.origin, and global_position with global_transform.origin.

  • BredemarBredemar Posts: 15Member

    Is it that simple?) How do you know all this? Thanks!
    Objects appear, but for some reason at a single point, and not in Path at all. I've been sitting for 1 hour and I can't understand why? A point from Path must be randomly selected and an object created there.

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    @Bredemar said:
    Is it that simple?) How do you know all this? Thanks!

    Happy to help! Most of what I've learned about Godot, especially on the 3D side, is through trial and error. It also helped I had quite a bit of Unity experience prior to the transition :smile:

    Objects appear, but for some reason at a single point, and not in Path at all. I've been sitting for 1 hour and I can't understand why? A point from Path must be randomly selected and an object created there.

    Hmm, I'm not sure what is going on. Can you post the code? Maybe something there is causing the issue.

  • BredemarBredemar Posts: 15Member
    edited July 13

    @TwistedTwigleg said:
    Hmm, I'm not sure what is going on. Can you post the code? Maybe something there is causing the issue.

    Hello. I'll try to explain what's going on here with my stupid English. In one of the lessons, I drew a curved line with Path and connected the PathFollow node. According to the lesson (which is 2D, but I do 3D) a random position with Path is chosen and the enemy will be filled there, but my enemies will be filled only in one point and not in Path at all! Here is all my code:

    extends Spatial
    
    export (PackedScene) var Enemy
    
    func _ready():
        randomize()
    
    func _on_Timer_timeout():
        $Path/PathFollow.offset = randi()
        var enemy = Enemy.instance()
        add_child(enemy)
        enemy.transform.origin = $Path/PathFollow.transform.origin
    
  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    Hmm, maybe try the following?

    extends Spatial
    export (PackedScene) var Enemy
    func _ready():
        randomize()
    func _on_Timer_timeout():
        $Path/PathFollow.unit_offset = randi()
        var enemy = Enemy.instance()
        add_child(enemy)
        enemy.global_transform.origin = $Path/PathFollow.global_transform.origin
    
  • BredemarBredemar Posts: 15Member

    WTF, how u do it???? Thanks!! You're the best!

  • BredemarBredemar Posts: 15Member
    edited July 13

    Ooops.

  • BredemarBredemar Posts: 15Member


    How to clean it all up?

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    @Bredemar said:

    How to clean it all up?

    You’re going to need to profile the project and try to figure out what is causing the performance loss. There isn’t really a standard answer here, it really depends on your project.
    Based on the picture, my guess is its something happening in _process that is causing the issue. I would look and see what scripts you have that execute code in _process and profile the code using the Godot Editor’s profiler, and see if you can narrow down what could be causing the issue. Loops and complicated/intensive calculations are usually the culprit, so I would initially focus on those.

  • BredemarBredemar Posts: 15Member
    edited July 14

    I don't know. I made a new project, optimized everything as much as possible - many objects at startup and starts lag(((.

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    Maybe see if reducing the number of objects helps? According to the picture a couple posts ago, you have 947 objects, which may be taxing the CPU. I would try reducing them and see if that helps. If that doesn't work, then I would disable everything as much as possible, and slowly start reintroducing it, carefully watching to see what causes a performance drop.

  • BredemarBredemar Posts: 15Member

    I have no objects at all. Once a second an object is created, flies to one point and is destroyed there. I don't understand where they came from!

  • MegalomaniakMegalomaniak Posts: 2,785Admin

    but is it really and properly removed from the scene tree?

  • BredemarBredemar Posts: 15Member
    edited July 14

    self.queue_free()

Leave a Comment

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