0 votes

I am working on a farming game, but I dont want to add crops to the same position or overwrite it. How can i prevent the overwrite part?

func _input(event):
if event.is_action_pressed("Plant") and self.get_cellv(tile_pos_infront_of_player) == CONSTANTS.SCRATCH_DIRT_ID:
    var crop_path = "res://Crops/Potato.tscn"
    var crop = load(crop_path).instance()
    crop.initialize(crop_data)
    crop.global_position = tile_pos_infront_of_player * 16
    add_child(crop)

If you need more information for code let me know

in Engine by (12 points)

1 Answer

0 votes

Maybe I am confused with the question but the obvious would be to set the position by changing tile_pos_infront_of_player to something like this below:

# Calculate a new position you want crop to appear
crop_position = Vector2(500,500)
crop.global_position = crop_position * 16
add_child(crop)
by (805 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.