distance to target object||doc135428

September 20, 2022

Format

 Object:distance(obj) 
  • The class to which the function belongs:Object

Description

Calculate the distance between the object and the target object, and return the distance value.


Parameters

Variable name type Description
obj Object target


Value Returned

type Description
float distance


Code Samples

On the server side of the entity objectmount script, add the time when the registered entity diesCallback, if the murderer exists thenbroadcast tipsdistance between the two

Trigger.addHandler(this:cfg(), "ENTITY_DIE", function(context)
   local from = context.obj1
    local to = context.obj2
    if to and to:isValid() then                   --Does the murderer exist?
       local dis =  from:distance(to)
       World.CurWorld.SystemNotice(1, dis, 40)    --Broadcast
    end
end)