• 🏆 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!

Region Teleportation Based on Closest Points

Status
Not open for further replies.
Level 3
Joined
Nov 3, 2015
Messages
42
Imagine a horizontal mountain range that spans the entire length of the map with no way over or around for ground or sea units. The only way for them to access the other side of this mountain is to enter a tunnel, of which there are many to choose from. Instead of creating two regions for each side of a tunnel, I have instead opted for two regions for each side of the mountain range to make things less complicated for myself.

What I want is for a unit to enter Region A and move instantly to Region B, but keeping the same X or horizontal coordinate -- as if the unit just moved forward until they found themselves at the opposite end of a tunnel.

Center of Region and Random Point In Region will obviously not fit.
 
Level 20
Joined
Aug 29, 2012
Messages
826
Maybe you could calculate the distance between the position of the unit and the target point (it would have to be an average, like the center of your region B), and then use "Conversion - Coordinates to point" to move your unit to (current X coordinates + calculated distance). It won't be 100% accurate, but I guess it'd move the unit horizontally for the correct distance.

Not sure if that's clear though. That's not an easy problem.
 
Level 13
Joined
Oct 12, 2016
Messages
769
It's mostly a case of doing what Chaosium suggested with "conversion - coordinates to a point" then doing some subtraction.
You would then set the new point at the cave exit to an "arithmetic" value with that offset factored in.

Make sure you also remove those points to avoid memory leaks (and in turn, gradual lag) in your map:
Things That Leak


To simplify what I mean, here is a crappy diagram for graphing coordinates:

-----------------|
(0,5)-----------|
--|------------>|
--|------>------|
-R|---->--------|F
--|
-S|
(0,0)---------(0,17)

let R = y-coordinate reference point = 3
S = start point y = 1
F = finish point y
Fy = Ry - Sy + 1
Fx = 17
Therefore: F(x,y) = (2,17)

You can set the point to those coordinates.
For your map, you will just have to find the constant "X" value for either side of the cave, or offset the "y" value from the center of your region.
 
Last edited:
Level 3
Joined
Nov 3, 2015
Messages
42
Code:
TP1AND2
    Events
        Unit - A unit enters Region1 <gen>
        Unit - A unit enters Region2 <gen>
    Conditions
        ((Triggering unit) is A structure) Equal to False
        ((Triggering unit) is A flying unit) Equal to False
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Region1 <gen> contains (Triggering unit)) Equal to True
            Then - Actions
                Set TempPoint = (Position of (Triggering unit))
                Set TempNewPoint = (TempPoint offset by (0.00, 600.00))
                Unit - Move (Triggering unit) instantly to TempNewPoint
                Custom script:   call RemoveLocation(udg_TempPoint)
                Custom script:   call RemoveLocation(udg_TempNewPoint)
            Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Region2 <gen> contains (Triggering unit)) Equal to True
                    Then - Actions
                        Set TempPoint = (Position of (Triggering unit))
                        Set TempNewPoint = (TempPoint offset by (0.00, -600.00))
                        Unit - Move (Triggering unit) instantly to TempNewPoint
                        Custom script:   call RemoveLocation(udg_TempPoint)
                        Custom script:   call RemoveLocation(udg_TempNewPoint)
                    Else - Actions
                        Do nothing

Before I read your suggestions, I made this and was wondering why it only worked for Region1 --> Region2.

Anyway, I'm going to try and find out how to do your suggestions.
 
Status
Not open for further replies.
Top