0 votes

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 :)

the script:

func kill():

var m = med.instance()
get_parent().add_child(m)
m.position = position
in Engine by (77 points)

1 Answer

0 votes

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)))
by (3,233 points)

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.)

So something like this?

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

Thank you a lot!!!

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 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.