map_to_world in Godot 4
Asked Answered
C

3

0

Hey all, I'm trying to get a simple grid based navigation system for my game working and I found this really great tutorial that does everything I need, but its outdate (4 years old) The code largely seems to be find when converting to 4.2, except for one that I can't find the proper replacement for, or I have but it doesn't work.

Here's the tut:

There's a part in the code where I am getting the local point of a node with this code:
astar.add_point(ind, gridmap.map_to_world(cell.x, cell.y, cell.z))

but in 4 there is no function "map_to_world", its now "map_to_local". But when I switch to the new code I get this error:

Invalid call to function 'map_to_local' in base 'GridMap'. Expected 1 arguments.
I'm not sure what the problem is. Any ideas?

Capua answered 2/1 at 18:31 Comment(0)
Q
1

Instead of three arguments, the function combines them into one Vector3i:
https://docs.godotengine.org/en/4.2/classes/class_gridmap.html#class-gridmap-method-map-to-local

So try this:
astar.add_point(ind, gridmap.map_to_local(Vector3i(cell.x, cell.y, cell.z)))

Quick answered 3/1 at 3:27 Comment(0)
C
0

Quick That worked! And makes a lot of sense, the new function takes 1 argument rather than 3, so I just needed to combine them into a single variable. So simple that I miss it haha

Capua answered 3/1 at 14:54 Comment(0)
C
0

Quick I managed to get the rest of the code working too! Some small updates, nothing crazy. Edited the code slightly to suit my needs better too.

EDIT: I found the problem, wasn't the code. It was me lol. I did the inputs wrong.
One last ask on this topic, not sure if you would know the answer, if I click somewhere that has no navigation points at all (like a blank spot on the map) it doesn't find the nearest nav point to where I click. Does the func get_closest_point() not actually do that? Am I expecting that function to do more than I should be? Right now if I click outside of the nav area it just sets the first node with the correct X value as the node that is closest to where I clicked, which isn't even kind of accurate lol

Capua answered 3/1 at 19:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.