1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

How do you make fps projections?

Discussion in 'StarCraft II Modding' started by 4avenger5, Sep 19, 2010.

  1. 4avenger5

    4avenger5

    Joined:
    Nov 17, 2009
    Messages:
    29
    Resources:
    0
    Resources:
    0
    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.
     
  2. Bags159

    Bags159

    Joined:
    Aug 22, 2010
    Messages:
    34
    Resources:
    0
    Resources:
    0
  3. 4avenger5

    4avenger5

    Joined:
    Nov 17, 2009
    Messages:
    29
    Resources:
    0
    Resources:
    0
    Are you sure this is an fps shooting system? I'm kinda confused. :sad:
     
  4. splashy5

    splashy5

    Joined:
    Jul 22, 2007
    Messages:
    259
    Resources:
    0
    Resources:
    0
    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
     
  5. mrzwach

    mrzwach

    Joined:
    Aug 1, 2009
    Messages:
    929
    Resources:
    3
    Tutorials:
    3
    Resources:
    3
    Don't recalculate polar projections/tan for the same value 50 times. Needless inefficiency.

    Also, whats with the first loop? It doesn't even do anything.
     
  6. DarkPost

    DarkPost

    Joined:
    Jun 22, 2008
    Messages:
    61
    Resources:
    2
    Maps:
    2
    Resources:
    2
    This is when I realised triggering is some serious shit.
     
  7. M0RT

    M0RT

    Joined:
    Apr 15, 2008
    Messages:
    1,067
    Resources:
    6
    Maps:
    3
    StarCraft II Resources:
    1
    Tutorials:
    2
    Resources:
    6
    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).
    [​IMG]
    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 (Text):

    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
     
     

    Attached Files: