randomize object

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

Hi, I made a dead function for my ennemy and now I want to randomize the medkit the ennemy drop when he died but I don’t know how to do it.Thank for helping me :slight_smile:

the script:

func kill():

var m = med.instance()
get_parent().add_child(m)
m.position = position
:bust_in_silhouette: Reply From: Magso

If it’s the position you want to randomise you can use set_translation. Vector3 variables can be used to set the minimum and maximum positions.

export var min : Vector3
export var max : Vector3
m.set_translation(Vector3(rand_range(min.x, max.x), rand_range(min.y, max.y), rand_range(min.z, max.z)))

Thank that will be useful for something else but that not what I wanted to do.
It more like : when the enemy died the player have a chance to get a medic when the enemy died .(Its more something we the instance I think.for example 50% chance to get a medkit or 50% to not get a medic.)

thoma | 2019-06-23 20:09

So something like this?

var randomNumber : float
randomNumber = rand_range(0, 2)
if randomNumber > 1:
    #create med

Magso | 2019-06-23 22:54

Thank you a lot!!!

thoma | 2019-06-23 23:09