• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Detecting Distance

Status
Not open for further replies.
Level 9
Joined
Jan 17, 2009
Messages
372
Hi, i am making a trigger to check to see if there are any destrucibles blocking the camera. They problem i am having is when it finds distance it will find the distance from the destructible to the unit.
This isnt a problem unless the destructible is on an angle. I have a attached an image to help explain what i am trying to say.
 

Attachments

  • Screensho.jpg
    Screensho.jpg
    196.9 KB · Views: 163
Level 9
Joined
Jan 17, 2009
Messages
372
you want to have just the y-component? Or what? Eleborate please

i want it so the 2 black lines shown in picture will always be perpendicular, so i can find the distance of the black line with check mark next to it.

The region is going to be centered behind the footman when it is moving around. "Lines" are imaginary just trying to use them to help explain
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
what do x, f, m, and b stand for?
Also, if this is what i think it is then it wont work when the unit turns in a different direction.
It works for any line given that you actually know the formula (which is easy to work out). You would naturally have to recalculate the formula every time you checked.

If you have two points (a,b) and (x,y) {a≠x}, m and b are as follows:

m = (y-b)/(x-a)

b = y-mx = b-ma
 
Level 4
Joined
May 17, 2005
Messages
94
Well, I built a solution, but it's not very beautiful, and hopefully there's a better way to do this. Anyhow:

First, some definitions:
a = angle of the unit
u = x of the unit
v = y of the unit
k = x of the destructable
g = y of the destructable
r is the solution aka the distance from the destructable to the line extended perpendicularly from the unit

if a is equal to a multiple of 180, then:

r = Abs(k - u)

if a is equal to 90 plus a multiple of 180, then:

r = Abs(g - v)

if the value of a satisfies neither of those two conditions, a much uglier formula can be used. It will be split up for convenience; I used about 8 inches of paper writing it out fully in small writing otherwise.

t will be a variable defined for the sake of convenience and efficiency. It represents the solved x location of where the line from the destructable intersects the perpendicular line from the unit, and is defined as:

t = ((g - k*tan(a)) - (v - u*tan(a-90)))/(tan(a-90) - tan(a))

r = SquareRoot((k - t)^2 + (k*tan(a) - tan(a)*t)^2)




Granted, there's some compression that could be done (ie storing tan(a) and tan(a-90) to variables). As such, if you were to define h as tan(a) and j as tan(a-90), you would get:

t = ((g - k*h) - (v - u*j))/(j - h)

r = SquareRoot((k - t)^2 + (k*h - h*t)^2)

Which you could further simplify, thus winding up with the result of:

t = (g - k*h - v + u*j)/(j - h)
r = SquareRoot((k - t)^2 + (h*(k-t))^2)


Thus, your final result is:

if a is a multiple of 180 then:

r = Abs(k - u)

elseif a is 90 plus a multiple of 180 then:

r = Abs(g - v)

else

h = tan(a)
j = tan(a - 90)
t = (g - k*h - v + u*j)/(j - h)
r = SquareRoot((k - t)^2 + (h*(k-t))^2)




Note however that a region won't angle with a unit, thus you'll have to use a neato way to only pick destructables behind a unit when enumerating them in an area around the unit. Good luck and ask if you're not sure how to do that!
 
Level 9
Joined
Jan 17, 2009
Messages
372
Well, I built a solution, but it's not very beautiful, and hopefully there's a better way to do this. Anyhow:

First, some definitions:
a = angle of the unit
u = x of the unit
v = y of the unit
k = x of the destructable
g = y of the destructable
r is the solution aka the distance from the destructable to the line extended perpendicularly from the unit

if a is equal to a multiple of 180, then:

r = Abs(k - u)

if a is equal to 90 plus a multiple of 180, then:

r = Abs(g - v)

if the value of a satisfies neither of those two conditions, a much uglier formula can be used. It will be split up for convenience; I used about 8 inches of paper writing it out fully in small writing otherwise.

t will be a variable defined for the sake of convenience and efficiency. It represents the solved x location of where the line from the destructable intersects the perpendicular line from the unit, and is defined as:

t = ((g - k*tan(a)) - (v - u*tan(a-90)))/(tan(a-90) - tan(a))

r = SquareRoot((k - t)^2 + (k*tan(a) - tan(a)*t)^2)




Granted, there's some compression that could be done (ie storing tan(a) and tan(a-90) to variables). As such, if you were to define h as tan(a) and j as tan(a-90), you would get:

t = ((g - k*h) - (v - u*j))/(j - h)

r = SquareRoot((k - t)^2 + (k*h - h*t)^2)

Which you could further simplify, thus winding up with the result of:

t = (g - k*h - v + u*j)/(j - h)
r = SquareRoot((k - t)^2 + (h*(k-t))^2)


Thus, your final result is:

if a is a multiple of 180 then:

r = Abs(k - u)

elseif a is 90 plus a multiple of 180 then:

r = Abs(g - v)

else

h = tan(a)
j = tan(a - 90)
t = (g - k*h - v + u*j)/(j - h)
r = SquareRoot((k - t)^2 + (h*(k-t))^2)




Note however that a region won't angle with a unit, thus you'll have to use a neato way to only pick destructables behind a unit when enumerating them in an area around the unit. Good luck and ask if you're not sure how to do that!

the formula you gave me isnt really working but is T supposed to be done scientifically or just from left to right?
Here is trigger for you to check.
  • Camera
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer CamInt) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CameraOn[CamInt] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Destructible[CamInt] Equal to True
                • Then - Actions
                  • Set UseofCamD[CamInt] = True
                  • Set TempLoc = (Position of CameraUnit[CamInt])
                  • Set TempLoc2 = (TempLoc offset by (CameraDisNorm[CamInt] x 0.30) towards ((Facing of CameraUnit[CamInt]) - 180.00) degrees)
                  • Set TempRegion = (Region centered at TempLoc2 with size ((CameraDisNorm[CamInt] x 0.41), (CameraDisNorm[CamInt] x 0.41)))
                  • Custom script: call RemoveLocation(udg_TempLoc)
                  • Destructible - Pick every destructible in TempRegion and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Destructible-type of (Picked destructible)) Equal to Camera Blocker
                        • Then - Actions
                          • Set TempLoc = (Position of (Picked destructible))
                          • Set A[CamInt] = (Facing of CameraUnit[CamInt])
                          • Set U[CamInt] = (X of TempLoc)
                          • Set V[CamInt] = (Y of TempLoc)
                          • Set K[CamInt] = (X of TempLoc2)
                          • Set G[CamInt] = (Y of TempLoc2)
                          • Set Equation[CamInt] = True
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (A[CamInt] Equal to 180.00) or (A[CamInt] Equal to 360.00)
                            • Then - Actions
                              • Set R[CamInt] = (Abs((K[CamInt] - U[CamInt])))
                              • Set Equation[CamInt] = False
                            • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • A[CamInt] Equal to 270.00
                            • Then - Actions
                              • Set R[CamInt] = (Abs((G[CamInt] - V[CamInt])))
                              • Set Equation[CamInt] = False
                            • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • Equation[CamInt] Equal to True
                            • Then - Actions
                              • Set H[CamInt] = (Tan(A[CamInt]))
                              • Set J[CamInt] = (Tan((A[CamInt] - 90.00)))
                              • Set T[CamInt] = ((((((G[CamInt] - K[CamInt]) x H[CamInt]) - V[CamInt]) + U[CamInt]) x J[CamInt]) / (J[CamInt] - H[CamInt]))
                              • Set R[CamInt] = (Square root((((K[CamInt] - T[CamInt]) x (K[CamInt] - T[CamInt])) + ((H[CamInt] x (K[CamInt] - T[CamInt])) x (H[CamInt] x (K[CamInt] - T[CamInt]))))))
                              • Set CameraDisDestruc[CamInt] = R[CamInt]
                            • Else - Actions
                        • Else - Actions
                  • Custom script: call RemoveLocation(udg_TempLoc2)
                  • Custom script: call RemoveRect(udg_TempRegion)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RotationOn[CamInt] Equal to True
                • Then - Actions
                  • Camera - Set (Owner of CameraUnit[CamInt])'s camera Rotation to (Facing of CameraUnit[CamInt]) over 0.15 seconds
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • UseofCamD[CamInt] Equal to False
                • Then - Actions
                  • Camera - Set (Owner of CameraUnit[CamInt])'s camera Distance to target to CameraDisNorm[CamInt] over 0.15 seconds
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • UseofCamD[CamInt] Equal to True
                • Then - Actions
                  • Camera - Set (Owner of CameraUnit[CamInt])'s camera Distance to target to CameraDisDestruc[CamInt] over 0.15 seconds
                  • Set UseofCamD[CamInt] = False
                • Else - Actions
              • Camera - Set (Owner of CameraUnit[CamInt])'s camera Angle of attack to CamAoA[CamInt] over 0.15 seconds
              • Camera - Set (Owner of CameraUnit[CamInt])'s camera Height Offset to CamHeight[CamInt] over 0.15 seconds
            • Else - Actions
 
Level 4
Joined
May 17, 2005
Messages
94
temploc and temploc2, in the spots when the formula is being calculated, are wrong. The way you have it, temploc should be the position of the unit, temploc2 should be the position of the destructable.

And yes, t is supposed to be done with recognition of order of operations. Hence why I put the parenthesis there.

0 should also be included in the check for 180 or 360. 90 should also be included in the check for 270.


That should fix it, I think. I know the formula I posted works because I double checked my typing and intensively tested it on my calculator.

edit: you should also be setting the camera distance to the lowest r generated, not simply the final one enumerated.
 
Level 9
Joined
Jan 17, 2009
Messages
372
temploc and temploc2, in the spots when the formula is being calculated, are wrong. The way you have it, temploc should be the position of the unit, temploc2 should be the position of the destructable.

And yes, t is supposed to be done with recognition of order of operations. Hence why I put the parenthesis there.

0 should also be included in the check for 180 or 360. 90 should also be included in the check for 270.


That should fix it, I think. I know the formula I posted works because I double checked my typing and intensively tested it on my calculator.

edit: you should also be setting the camera distance to the lowest r generated, not simply the final one enumerated.
here is new and improved trigger, but i dont know how to check for lowest r generated. please help
 
Status
Not open for further replies.
Top