The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello. So, I'm using a Tileset to draw my map, but, some of those tiles need to have some behaviour. In this case some spikes that hurt the player.

I have those spikes as a scene, and imported it. It works fine, now, I would like to be able to have those spikes in different rotation, so I don't have to have 4 different scenes changing only that.

Is it possible? Or, is it possible to add some kind of property to it and control it with a script?


Godot version 4.1
in Engine by (19 points)

1 Answer

0 votes

I dont use tilesets but did you try randomizing it in your spike scene ready function. Something like this :

func ready():
    rotation = Vector2(randf_range(0,360),randf_range(0,360))
by (600 points)

Sorry this was meant to be a comment. I wasnt aware that I clicked the answer button. :|

Hey! Thanks but that's not a possible solution. The reason is that the spikes must be aiming up when they are on the ground, right/left, on a wall etc. I don't want it random haha.

The solution should be something like with a normal tile, that you can rotate or flip it. I can't find how to do it on a scene tile

I understand would something like this work then :

@export var is_on_wall : bool = true
@export var is_flipped : bool = false
func _ready():
    var random_direction : int = randi_range(0,3)
    var flip = 1 if is_flipped else -1
    if is_on_wall:
        rotation = Vector2(random_direction * 45, flip * 90)
        rotation = Vector2(0, random_direction * 45)

The thing is, can i set those variables from here in any way?

enter image description here

Otherwise, I still need to have 4 different scenes, one with each possible option, and would be the same that just rotating the sprite and not using the script.

I looked at the tileset documentation now and I guess this is the feature you want

No scripting is needed afterall.

Yes haha, I want exactly that. But, that works for when it's an atlas. In my case I need it to be an scene since the tile has it's own script and behaviour. If it's possible with scenes the option is not showing for me.

Actually the documentation talks about that too in here like assigning a damagepersecond variable :

Anyways I looked around and tried to search some similar questions but couldnt find anything. I dont use tilesets normally and I cant think of anything else either so I hope you find a solution soon!

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.