Hi, I'm actually trying to make a kind of ARPG script including buildings, but I'm having a weird trouble that I can't seem to solve, I may be dumb, but better ask than doing nothing :
I'm pressing a button to load a build_bar which contains every buildings I can build, then when I click on one, it will show a preview of the building where my mouse is, I'll update it for every frames to keep the preview under the mouse and then I'll verify if the place is valid, and then I'll build it.
But, when I added my camera 2D, the tower wasn't on my mouse cursor at all, and in fact, if my character was moving right, the tower would follow.. but not exactly. What I mean is it looks like the preview is connected somehow on the middle of the original viewport while following the movements of my mouse.
I'd like to have the tower follow only the mouse position.. but can't find it.
Here's the code I use when I press a button to select a building to build :
build_type = tower_type
build_mode = true
Then, to update this building preview, I'm doing this under process :
And the so called function :
var mouse_position = get_global_mouse_position()
var current_tile = map_node.get_node("TowerExclusion").world_to_map(mouse_position)
var tile_position = map_node.get_node("TowerExclusion").map_to_world(current_tile)
if map_node.get_node("TowerExclusion").get_cellv(current_tile) == -1:
build_valid = true
build_location = tile_position + Vector2(32, 32)
build_tile = current_tile
build_valid = false
I'm using Vector2(32,32) to center my building on a 64x64 tile.
And once I left click to valid it, I'm doing this one :
##Test to verify players has enough resources
var new_tower = load("res://Assets/Buildings/" + build_type + ".tscn").instance()
new_tower.position = build_location
new_tower.built = true
new_tower.type = build_type
So far, it's working really greatly. But then, I tried to use a Camera 2D on my character to make the viewport like it should be, and have a "bigger world".
My "player" is concepted like this :
Kinematic Body 2D
Camera2D (Zoom on 0.75 x and 0.75 y )
My initial viewport at the moment is 1920 x 1080.
Hope it was clear enough.. Thanks in advance for any help I could get !