1. How to obtain the distance to the animal in the LUA ???
     
  2. You can use: http://docs.unity3d.com/ScriptReference/Vector3.Distance.html I don't know if there is an example out there though.

    It should be something like this:
    local playerPos = player.transform.position
    local animalPos = entity.transform.position --You'll need to get the entity first.
    local distance = UnityEngine.Vector3.Distance( playerPos, animalPos)
    print("Distance to animal: " .. tostring(distance))
     
  3. I want the distance to the animal from which it was killed - could be defined as a variable and continue to use it as an example of the award in the amount of money equal to the distance!
     
  4. Yeah and what is stopping you from doing that? I gave you all the code you need to find the distance, you will need to figure out the rest.
     
  5. Code:
    local distance = UnityEngine.Vector3( playerPos, animalPos)
    Take off the 'Distance'.
     
  6. UnityEngine.Vector3 - don't work, but UnityEngine.Vector3.Distanc - work :)
    [DOUBLEPOST=1433183576][/DOUBLEPOST]How to round the value of the distance to the nearest whole number or two numbers after the decimal point?
     
    Last edited by a moderator: Jun 1, 2015
  7. Oh nvm mind you're right:
    Code:
        def distance(self, p1, p2):        return Vector3.Distance(p1, p2)
    
     
  8. How to round the value of the distance to the nearest whole number or two numbers after the decimal point?
     
  9. Wulf

    Wulf Community Admin

  10. I write, but nothing happens!
    function round(distance, idp)
    return tonumber(string.format("%." .. (idp or 0) .. "f", distance))
    end
    [DOUBLEPOST=1433196984][/DOUBLEPOST]
    Here shows the distance to all the animals, but not for as I kill!
     
  11. Code:
    local playerPos = player.transform.position
    local animalPos = entity.transform.position
    local distance = UnityEngine.Vector3.Distance( playerPos, animalPos)
    local rounded = math.floor(string.format('%.2f', num))print('Distance: ' .. rounded)
    
    I haven't test it, but should work.[/code]
     
    Last edited by a moderator: Jun 2, 2015
  12. Code:
            local xr = string.format("%.0f", animal.transform.position.x)
            local zr = string.format("%.0f", animal.transform.position.z)
            local xk = string.format("%.0f", player.transform.position.x)
            local zk = string.format("%.0f", player.transform.position.z)
            local dist = math.floor(math.sqrt(math.pow(xr - xk,2) + math.pow(zr - zk,2)))
            print(dist)
    also should work