• 2D
  • Node2d Scale impacting position

Hi,

For my 2d game I have a consolidated single file for textures. While placing sprites on the screen , I had to make few adjustments using the "Scale" options under Nod2d. Now I am spawning my bullet at runtime ( which is scaled to .5), now when I am placing the bullet its treating coordinates differently depending on what the scale factor is. For example is scale is 1 it treats coordinate of 500 as out of screen ( project setting resolution is 800*600), while its .5 its visible on screen. Any help with this would be great as scale should not impact position.

Thanks Vivek

I think Godot scales from the top left and gets Node2D's position from the center, so when the scale changes the position relative to the scene changes. So a value of 500 with a scale of 1 is slightly longer than a value of 500 with a scale of 0.5.

I'm currently away from my computer, so I cannot test, but I think that is why your seeing that effect.

(Disclaimer: I mainly use Godot for 3D, so I might be completely wrong :D )

Thanks TwistedTwigleg :), I worked on that problem a lot now, still no resolution. So I have two scenes , first scene is with the main elements, the background the player etc. The second scene is just bullet with its own code and its own draw method ( I am just using a plain rectangle). Now I have made everything as Pos - 0,0 and Size 1,1 in my bullet scene. I am using a node to spawn my bullets on my main scene, I am spawning my bullets to my gun's position, the system is placing my bullets out of screen. Viewport size on debug-print is still 800*600( which is correct), but If I position my bullets @ 750,650 its out of bounds. Any clue what might be causing that. Hope I was able to explain the situation a bit better.

Thanks

Ok resolved the issue. Issue was when I was drawing my rectangle in bullet scene. I was using x,y coordinates by using coordinates from its parent ( or whatever the parent will be ), but this is not working correctly, which I think it should. Anyway so I used 0,0 to draw my rectangle as anyways I was going to re position it. This resolved my issue.