• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Question: Place unit out of specific Region

Status
Not open for further replies.
Level 2
Joined
Dec 6, 2018
Messages
10
Hey guys, hope you can help me on this :)

I try to do an event in Wurst-Script that periodically spawns some units on a random point of the playable map area. Now i want to check if the picked point would be in a 1000 radius of any players starting location and than pick a point out or on the border of that radius. My idea is to do some calculations with a dummy, but i have no clue how i can get a point out of the 1000 radius, or of the 1000 radius border.

I would be glad if someone can give me some tips to achieve this :)

Best regards
 
Level 2
Joined
Dec 6, 2018
Messages
10
Thanks for your input :)

I have done some maths and created this, it works very well :)

It calcs the nearest point for the radius definition

Code:
function calcPointOutOfRegion(location spawn, location start, real radius) returns location
    real x1 = GetLocationX(start)
    real x2 = GetLocationX(spawn)
    real y1 = GetLocationY(start)
    real y2 = GetLocationY(spawn)

    real r = radius

    real m = (y2 - y1) / (x2 - x1)

    real b = y1 - (m * x1)

    real xnew1 = (m*y1 - m*b + SquareRoot(Pow(m, 2)*Pow(r, 2) - Pow(m, 2)*Pow(x1, 2) + 2*m*x1*y1 - 2*m*b*x1 + 2*b*y1 + Pow(r, 2) - Pow(b, 2) - Pow(y1, 2)) + x1) / (1 + Pow(m, 2))
    real xnew2 = (m*y1 - m*b - SquareRoot(Pow(m, 2)*Pow(r, 2) - Pow(m, 2)*Pow(x1, 2) + 2*m*x1*y1 - 2*m*b*x1 + 2*b*y1 + Pow(r, 2) - Pow(b, 2) - Pow(y1, 2)) + x1) / (1 + Pow(m, 2))

    real ynew1 = m * xnew1 + b
    real ynew2 = m * xnew2 + b

    real DistanceOfP1 = DistanceBetweenPoints(Location(xnew1, ynew1), spawn)
    real DistanceOfP2 = DistanceBetweenPoints(Location(xnew2, ynew2), spawn)

    return DistanceOfP1 <= DistanceOfP2 ? Location(xnew1, ynew1) : Location(xnew2, ynew2)
 
Status
Not open for further replies.
Top