randomizing offset

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By witch_milk

Hi , I have animated a 3D sprite to move upwards and then fade away with translation and modulate. This sprite is instanced a lot and I want each one to have a random offset so that they are all readable. As of now they almost layer onto of each other.
I do not know which value to change in my script.

My set up is animated
sprite 3D
Viewport
richtext label (node with desired offset change i am thinking)
I have tried this but it did not work:
randomize() #new

var offset_x
	offset_x = randi()%100+1 #get random value between 1 -100 for offset?
	#$Viewport/RichTextLabel.position.x = offset_x # set off set?

maybe the property name is not offset_x, I do not know what it is.

:bust_in_silhouette: Reply From: jgodfrey

I think you’re after something like:

var offset_x = randi()%100+1
$Viewport/RichTextLabel.rect_position.x += offset_x

Note, that’s setting the x component of therect_position property of the RichTextLabel.

Also, the += there is adding the random offset value to the current position of the label. If, instead, you want to literally set the position of the label the to random value, change the += to just an =.

thank you. this worked and did what i was looking for.

witch_milk | 2020-10-26 03:56