+1 vote

When you press certain buttons in my game, the tilemap (with enemies and objects that touch the ground but without the player) is flipped horizontally or vertically.
To make it, i did this:
extends Node2D

 func _process(delta):
    if Input.is_action_just_pressed("ui_accept"):   #For now "ui_accept".
        if $TileMap.scale.y == 1:
            $TileMap.scale.y = -1
            $TileMap.scale.y = 1
    if Input.is_action_just_pressed("ui_cancel"):   #The same as before.
        if $TileMap.scale.x == 1:
            $TileMap.scale.x = -1
            $TileMap.scale.x = 1

But there's a problem:

When my tilemap it's flipped horizontally, vertically or both, the coordinates of the player don't coincide with the sprite and collision shape (because is not flipped along with my tilemap) so my game detects if the player is stuck in tiles i.e in -23, 22 instead of 22, -23 like it should be.
I tried this:

var a = $TileMap.world_to_map($Player.get_position() - Vector2(-1820, 896))
var b = $TileMap.get_cellv(a)

But when i move forward, character's x position it's 21 when it should be 23 (the same vertically). Is there a way to flip the coordinates and not my character along with the tilemap?

in Engine by (122 points)

Please log in or register to answer this question.

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.