Help with viewport and Origin(0,0)

Godot Version

V4.4.1

Question

Noob here, im trying to create some pathfinding for my tactics game prototype, u ran some code to detect a tile and print its coordinates. Whenever i run it an click on a tile it says its “out of bounds” i realized this happened because my grid was not at (0’0) and instead was in the of my viewport (which is 1920,1080).

Is there any way for me to move my origin to the center of my viewport? It’s really annoying to have to move all my assets to viewport center everytime and now this origin nonsense is screwing my pathfinding over. :^(

If possible i would also like some clarity regardjng the use the viewport. Is it actually the window my game is in or does it just represent that window? I tried moving the camera onto 0’0 and that worked but that means i’d have to do that with EVERY scene i made before. So does this mean the camera acts a proxy viewport? Anyway if theres a method to move 0’0 to viewport center please let me know!

-Mechode

I apologize for my ignorance in advance

It sounds like you are trying to do everything by yourself instead of relying on Godot to do things for you. Hard to say for sure without seeing your code or node structure though. It would help if you actually descried the problem you are having. You didn’t even mention if this is a 2D or 3D game. I get you are frustrated, and if you’re just venting, that’s cool. But if you’re not…

  1. Is this a 2D or 3D game?
  2. Why are you tring to roll your own pathfinding? Did NavigationAgent2D/3D and NavigationRegion2D/3D not work for you?
  3. Are you using global coordinates or local coordinates?
  4. Why did you have to move your camera to (0,0) and was that local or global coordinates?
  5. It sounds like you are trying to use global coordinates with your TimeMapLayer. Is there a reason you’re not using relative coordinates?
  6. Are you using a TileMap or a TileMapLayer?
  7. What’s your code look like?
  8. What’s your node structure look like?
1 Like

Sorry if i came off as venty. Im just not very versed in this sorta stuff.

  1. The game is 2D

  2. Im not using Navigation2D or whatever the other thing was, actually i have no idea what those are (gasp)

  3. I think i’m using global coordinates, i have no clue how to tell or use local coordinates.

  4. I moved it because my 0,0 is at the top left of the screen and not inside my viewport (which is 1920x1080) so i just made a camera and put it in the middle of 0,0

  5. Don’t know what that is (i am a noob)

  6. Tilemaplayer (i thought Tilemaps became irrelevant in godot 4?)

  7. Im following a tutorial for grid based moved with Astar pathfinding.


Sorry about the image, im typing this on my phone :^v

  1. Tilemap(Root)>Tilemaplayer>characterbody(w/script)>Collisionshape2d>Animatedsprite2d>AnimationPlayer>Camera.

Thank you for your swift reply and apologies for my late respone. (╥﹏╥)

By the way, i (think) i found a serviceable solution which just involves me moving everything to 0,0 and using cameras. But if theres any insights and solutions that a pro like you might have i am open to it.

1 Like

Using AStar is fine, but it’s basically getting geeky about math for fun. If you continue to have issues with it, I recommend checking out tutorials on NavigationAgent2D and NavigationRegion2D. They do all the heavy lifting for you and are much easier to use.

1 Like

Huh, thats odd, because all im hearing about is Astar.

Thank you for your time.

From whom?

Just generally the internet and youtube.
I forgot to mention im making a tactics game akin to fire emblem and disgaea which has multiple units. Whoops.

That might be why i’m hearing only about Astar, maybe its best suited for that.

Perhaps. I know nothing about either of those games.

Keep in mind that a lot of people come from other game engines and so they do tutorials based on the knowledge they have. AStar is a common algorithm. That’s why it’s popular.

1 Like

I will say the post did have to 2D tag so the information for that was out there.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.