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

How do you make fps projections?

Status
Not open for further replies.
Level 3
Joined
Nov 17, 2009
Messages
30
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.
 
Level 10
Joined
Jul 22, 2007
Messages
261
Using this will find the unit in the path of your cursor by using you Pitch and Yaw, also works for unit height

  • Traceline
    • Options: Action
    • Return Type: (None)
    • Parameters
      • Camera Position = No Point <Point>
      • Camera Height = 0.0 <Real>
      • Player = 0 <Integer>
    • Grammar Text: Traceline(Camera Position, Camera Height, Player)
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
      • A = 0 <Integer>
      • Pitch = (Current camera pitch of player Player) <Real>
      • Yaw = (Current camera yaw of player Player) <Real>
      • Trace Height = 0.0 <Real>
      • Trace Distance = 0.0 <Real>
      • Trace Point = No Point <Point>
      • Trace World Height = 0.0 <Real>
      • Trace Region = No Region <Region>
      • Unit Region = No Region <Region>
      • Closest Unit = No Unit <Unit>
      • Unit World Height = 0.0 <Real>
    • Actions
      • General - For each integer A from 1 to 50 with increment 1, do (Actions)
        • Actions
          • General - While (Conditions) are true, do (Actions)
            • Conditions
              • Trace Distance < 50.0
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • Pitch < 90.0
                • Then
                  • Variable - Set Trace Height = (* ((Tan(Pitch)), Trace Distance, -1.0))
                • Else
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • Pitch > 270.0
                    • Then
                      • Variable - Set Trace Height = ((Tan((360.0 - Pitch))) * Trace Distance)
                    • Else
              • 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
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
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).
attachment.php

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
 

Attachments

  • line.gif
    line.gif
    8.2 KB · Views: 528
Status
Not open for further replies.
Top