A Star Help

totorototoro Posts: 8Member
edited March 27 in Programming

Hi,
I've sort of rehashed this tutorial: , to use a 3 button mouse

It worked, until I tried to be able to remove obstacles, see the addObstacle() function.

Any help greatly appreciated!

.
.
.

It's a basic setup

  • A 3d world with a base Spatial node named World
  • Add 3 GeometryInstance's named Grid, Obstacles and DrawPath
  • Add a Spatial (named CamPivot) and a Camera as its child

.
.
.

The Camera script is:

extends Camera

const ray_length = 1000

func _input(event):
    if event is InputEventMouseButton and event.pressed:    # and event.button_index == 1:
        var from = project_ray_origin(event.position)
        var to = from + project_ray_normal(event.position) * ray_length
        var space_state = get_world().direct_space_state
        var result = space_state.intersect_ray(from, to, [], 1)
        if result:
            var o = get_tree().get_root().get_child(0)
            o.clicked(result.position, event.button_index)

.
.
.

The World script is:
https://gist.github.com/little-totoro/fe8127bddb69cb30b391d93e924a7cdb

Answers

  • SIsilicon28SIsilicon28 Posts: 286Member
    edited March 27

    Word of advice: don't copy in such a large amount of code into a post. Keep it short. If you need to show off all the code, I suggest you just link to it via a code hosting site such as GitHub gist.

  • MegalomaniakMegalomaniak Posts: 2,028Admin

    gist and pastebin url's pasted into posts get auto embedded. ;)

  • fire7sidefire7side Posts: 54Member
    edited March 27

    It's really hard to go over someone else's code. Hopefully go back to the part where it worked. Then make incremental changes and test them before you move on. I looked at this guys code on a different tutorial when I added astar, but then decided to write it myself. That's the best way to learn. I made mistakes, and I wondered what in the world was going on, but it was the way I had done my connections. Gave me results that were bonkers.

  • totorototoro Posts: 8Member

    Hi, thanks all

    Link for main script: https://gist.github.com/little-totoro/fe8127bddb69cb30b391d93e924a7cdb

    @fire7side I've read up a bit today and been through another more modern tutorial tonight, I intend to debug this code (it's only the removing of obstacles that is off (probably as simple as a miscalculated ID)), however I've rushed off to start from scratch, as you may see from my next post...

Leave a Comment

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