Teleport distance

In this code I want an entity to teleport to a random place throughout the map when I am a certain distance away from it. I have tried using enemy AI but it would not work. Somebody please help me with it.

Hi @Mason_Rocchio! If you have something from an example that is not working for you, please show your setup and code. Then we can take a look at it to see what could be wrong. Otherwise you will probably get the same example as an answer on your question.

1 Like
new temp pc.Vec3 
length(50);
if(this d = distance < 50);
this.entity.enebled = false;

if(this d = distance > 50);
this.entity.enebled = true;

I could tell from the moment I put this code in it was wrong. So I came to the forum

Screenshot 2022-03-08 8.35.03 AM
Screenshot of code and where errors are located

Where did you find this example?

Iā€™m not sure what your logic is exactly, but I think if I translate your code into something that is correct it would look like something below.

var distance = this.entity.getPosition().distance(targetEntity.getPosition());

if (distance < 50) {
    this.entity.enabled = false;
}

else {
    this.entity.enabled = true;
}
1 Like

so this is the correct coding

I knew the layout was wrong