Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
What im trying to do is make a 3rd person shooter game right. The problem is I dont know how to make fps projections! What I need is to make so you can isntantly shoot someone with a pistol when you left click. Also I need to make for another gun(not sure yet) to make so you shoot a beam. Thanks. Also this is for SC2 not for war3.
Variable - Set Trace Point = (Camera Position offset by Trace Distance towards Yaw degrees)
Variable - Set Trace World Height = (Ground height at Trace Point)
Variable - Set Trace Region = (Region(Trace Point, 1.5))
Variable - Set Closest Unit = (Closest unit to Trace Point in (Any units in Trace Region owned by player 15 matching Excluded: Missile, Dead, Invulnerable, with at most Any Amount))
Variable - Set Unit Region = (Region((Position of Closest Unit), (Closest Unit Radius (Current))))
Variable - Set Unit World Height = (Ground height at (Position of Closest Unit))
General - If (Conditions) then do (Actions) else do (Actions)
If
Closest Unit != No Unit
Closest Unit != Main Unit[Player]
(Trace Point is in Unit Region) == true
((Camera Height + Trace Height) - Unit World Height) >= 0.0
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
(Unit type of Closest Unit) == Infested Terran (Campaign) (ID is InfestedCivilian)
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
((Camera Height + Trace Height) - Unit World Height) <= 1.0
Then
Variable - Set traceline_CurrentTarget[Player] = Closest Unit
Variable - Set traceline_CurrentTargetPoint[Player] = Trace Point
Variable - Set traceline_CurrentTargetHeight[Player] = (Camera Height + Trace Height)
General - Custom Script: return;
Else
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
((Camera Height + Trace Height) - Unit World Height) <= 0.7
Then
Variable - Set traceline_CurrentTarget[Player] = Closest Unit
Variable - Set traceline_CurrentTargetPoint[Player] = Trace Point
Variable - Set traceline_CurrentTargetHeight[Player] = (Camera Height + Trace Height)
General - Custom Script: return;
Else
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
(Camera Height + Trace Height) <= Trace World Height
Then
Variable - Set traceline_CurrentTarget[Player] = No Unit
Variable - Set traceline_CurrentTargetPoint[Player] = Trace Point
Variable - Set traceline_CurrentTargetHeight[Player] = (Camera Height + Trace Height)
General - Custom Script: return;
Else
Variable - Modify Trace Distance: + 0.5
Variable - Set traceline_CurrentTarget[Player] = No Unit
Variable - Set traceline_CurrentTargetPoint[Player] = No Point
Variable - Set traceline_CurrentTargetHeight[Player] = 0.0
after this you just see if Traceline_CurrentTarget(X) is no unit or not if not then see if Traceline_CurrentPoint(X) is no point, if not do nothing
Both methods you posted here are horribly inefficient. Only difference is that the tutorial Bags159 linked to is using data editor and the trigger is doing the exact same calculations, but in script. The problem here is the (closest unit to point) function, that propably cycles through every unit in map and compares distance. 50 times!
What you should do is use Point to line distance formula, and apply this formula to every unit in possible area (the orange circle).
This way, you will reduce calculations to ONE "pick units" and some calculations (calculating distance are two multiplikations and 3 additions - very fast)
The formula itself: First, you need to calculate the line vector. If you have unit facing, the vector is ( Sin(face), Cos(Face) ). Then you convert it to normal vector (which is perpendicular to the line vector) - switch the both values and multiply one of them by -1.
You will get something like (Cos(face), -Sin(face) ). Now it's really easy.
If you calculate dot product, you will get distance from line (dot product - multiply X with the first number (Cos), y with the second (-Sin) and add them both - very simple).
So the last step is easy, calculate distance of the attacker position and compare it with targets position to get the real distance
Code:
x1 = Cos(facing)
y1 = - Sin(facing)
attackerDist = (X of Attacker) * x1 + (Y of Attacker) * y1
Pick all units in the area ( circle, radius is range/2, center is (Position of attacker)+(-y1*range/2,x1*range/2) )
distDiff = (X of PickedUnit)*x1 + (Y of PickedUnit)*y2) - attackerDist
if( Abs( distDiff ) < shotRadius )
target = picked unit
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.