0 votes

I want to decrease the health of my player about one, if he is above a specific cell. And if he is above it i want to change it to another cell. I did it already, but the problem is that if my player is above this specific cell, the health decreases about 5 or 4. I thought it is because of the function "process(delta)". But i only decrease the health if the cell is 1 and directly after it i change the cell to 0. So if it runs again it should not decreas. Then i thought maybe the "process(delta):" is faster than the update of the tilemap and now i am searching for a methode to update the tilemap dircetly after i changed the cell to 0.

My code:

func setTrace():
var tileMap = get_parent().get_node("traces")
var cellPos = tileMap.world_to_map(Vector2(position.x, position.y))

if tileMap.get_cellv(Vector2(cellPos.x / 4, cellPos.y / 4 + 0.4)) == 1:
    health = health - 1

tileMap.set_cellv(Vector2(cellPos.x / 4, cellPos.y / 4 + 0.4), 0)
in Engine by (14 points)

Cannot reproduce: your code works fine on my end. Can you provide an example project? Maybe the problem is somewhere else...

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 webmaster@godotengine.org with your username.