|
|
|
 |
Reply From: |
Omar13 |
¿Do you necessary need to put your “danger” tileset inside that TileMap?
I think the better approach is:
Scene
(TileMap)TileWorld → Tilset1, Tileset2… TilesetN
Scene
(TileMap)TileDanger → Tileset1, Tileset2… TilesetN
Add this last tilemap into a “danger” group
Then add the damage logic inside the player
func damage() -> void:
for i in get_slide_count():
var collision = get_slide_collision(i)
if collision.collider.is_in_group("danger"):
die()
check in documentacion get_slide_count() and get_slide_collision() so you can understand what is doing (and maybe improve the code)
“die()” is whatever func you want to implement
whit this you can instanciate this scenes in any other scene with your player
Scene
Node
Node
Player
TileMapDanger
TileMapWorld
Thanks a lot, so i made my tiles in a new Scene and everything works fine. One problem occured, maybe you can help me with it.
I added this to my player code
for i in get_slide_count():
var collision = get_slide_collision(i)
var danger = get_parent().get_node("Danger")
if collision.collider == danger:
get_tree().change_scene("res://World1.tscn")
My function now looks like this.
I have 2 scenes, World1 and World2 where i instanced the Danger tiles, the World tiles and my Player.
how do i write the last line:
get_tree().change_scene("res://World1.tscn")
so that it changes to the root node of the current scene.
So when i collide in World1 with my Danger tiles my World1 scene reloads and
when i collide in World2 with my Danger tiles my World2 scene reloads.
thank you very much for your answer
sprengerjan | 2020-05-02 14:43
make an export var (export var allow you to change that var from editor)
export var next_level := ""
…
…
get_tree().change_scene(next_level)
so in the world1 you can modify your player on editor (editable children) and put res://World2.tscn on the editor
on world2 same thing but res://World1.tscn
Omar13 | 2020-05-02 15:35
thank you very much Omar, that really helped a lot and gave me a tool to work with other things that bothered me 
grazie mille
sprengerjan | 2020-05-02 18:17