Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Accessing camera class from player controller

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    solid snake that's my problem right now , i don't know how to create a class instance, that's why i made the mistake creating a variable instead of a class instance.
    can you somehow fix the code i posted? that will help me a lot , thanks!

    Comment


    • #17
      You need to have both the variable, and the class instance. Without knowing more about what you are doing with that class, it is hard to say the best way to do it... But you will porbably want to make FreeAimControl a class variable, then spawn an instance somewhere in your code... Maybe this will help you:

      Code:
      var TPSPlayerController2 FreeAimControl;
      
      simulated function PostBeginPlay()
      {
          FreeAimControl = Spawn(Class'TPSPlayerController2', self);
      }
      
      simulated function Tick(float DeltaTime)
      {
          if(FreeAimControl != None)
          {
              FreeAimControl.FreeAim(DeltaTime);
          }
      }

      Comment


      • #18
        there already IS a game instance created...

        to reference it depends on WHERE you are located at the moment. What type of object you are in... if you're in an instance of the PlayerController, then you just have to say 'self'. But say if you're elsewhere you need to find out if that object has a reference to it, and access it. For instance, the GameCamera has a reference to the PlayerController that owns the camera... self.PlayerController.

        If all else fails you can grab one of them from the WorldInfo. This is there is possibly several instances existing at the same time (for all the current players). If it's a 1 player game though, you should be sure only 1 exists.

        Code:
        local MyPlayerControllerClass PC;
        
        foreach WorldInfo.DynamicActors(class'MyPlayerControllerClass', PC)
        {
             break;//stop looping on the first grab because that's the one we want
        }
        
        PC.DoSomething();

        Comment


        • #19
          Originally posted by Blaaguuu View Post
          You need to have both the variable, and the class instance. Without knowing more about what you are doing with that class, it is hard to say the best way to do it... But you will porbably want to make FreeAimControl a class variable, then spawn an instance somewhere in your code... Maybe this will help you:

          Code:
          var TPSPlayerController2 FreeAimControl;
          
          simulated function PostBeginPlay()
          {
              FreeAimControl = Spawn(Class'TPSPlayerController2', self);
          }
          
          simulated function Tick(float DeltaTime)
          {
              if(FreeAimControl != None)
              {
                  FreeAimControl.FreeAim(DeltaTime);
              }
          }
          That's just going to create a second PlayerController... the game already created one. This would be useless as it's not the player controller that already exists...

          Comment


          • #20
            You can also directly call a function of any class, without an instance, as long as the function is declared as "static", which comes with certain restraints, which I believe are covered on UDN.

            class'TPSPlayerController2'.Static.FreeAim(DeltaTi me);

            But chances are that wont work for what you are trying to do, because of those restraints on static functions.

            Originally posted by lordofduct View Post
            That's just going to create a second PlayerController... the game already created one. This would be useless as it's not the player controller that already exists...
            yeah, It's not the best example using a PlayerController, and perhaps that was cunfusing using his classes/vars, but I was just trying to show hwo one uses variables taht are actualyl just references to objects.

            Comment


            • #21
              the restraints on static functions is specifically that it has to be declared static, and that anything the static function does only effects the state of the class and not the instance.


              ...

              I'm assuming a lot of people here haven't fully understood the 'what' of a class.

              It's fairly basic, I like the 'car' analogy... actually here is a very short quote of how I described it earlier today on another forum:

              Classes are the definitions of some type of object. They implement some code structure, can extend some other class type, and much more. These are not the objects themselves...

              Think of them as the "blueprints" to some group of objects that are related by type. Like the blueprints to the same model car, from which you can fashion several cars... you can furthermore customize them after manufacturing by painting them, adding leather, etc etc.


              Instances are the instances of this class type. When you "construct" some class type, the instance is the result. You can have as many instance of the same class as you want (unless the class is defined otherwise, see Singleton). In the case with the car, it is each car made.

              For instance I own a Ford Focus ZX3. There are thousands of Ford Focus ZX3. The class of this car is "Ford Focus ZX3", my car just happens to be an 'instance' of this type of car.
              From this you can understand the issue with 'creating a new' instance or 'spawning a new' instance of a class. If I wanted to get into my car, I wouldn't build a whole new car... I'd go out and locate it and get in. I would only build a new car if I needed a second car for some reason (maybe give it to my girlfriend).


              Also, keep in mind, the "spawn" method of constructing a new object from a class is ONLY for Actors. See Actor's have several steps that are required for creating them, of which they don't handle themselves. Actor's need to be created first off, then have several steps taken on them... and after each step fire an event in the Actor. These steps are like logging in, connecting to server, putting the object into the WorldInfo so it can be displayed on screen, etc etc etc.

              Classes that don't extend Actor don't need all this done because they aren't Actors! They don't have this kind of stuff required of them. They are created with the 'new' keyword:

              Code:
              local SomeType obj;
              
              obj = new class'SomeType';

              in UnrealScript this all looks weird syntactically... to give a new comparison here's how java would do it:

              Code:
              SomeType obj = new SomeType();//<- this insinuates the call of a function... which actually it does because Java has what are called constructor functions
              the 'new' command is what tells the runtime to put aside some memory in the heap so that we can place a new object in there. Then it runs the constructor method which builds the object from the blueprint. And then it is placed into memory onto the heap.


              Spawn(...) on the otherhand is what is called a "factory function". It's what does a bunch of manwork for you. Not only does it create a 'new' instance, but sets up a bunch of other stuff for it as well. Instead of requiring you to do all the manwork EVERY time you wanted a new Actor... this "factory function" does it for you. Why? Because all Actor's have the same crap done to it when built.

              Comment


              • #22
                thanks for your help , now i have this:

                at the beggining of my player's class:
                Code:
                var  TPSPlayerCamera FreeAimCam ;
                then in my function:

                Code:
                local class<TPSPlayerCamera> newCam;
                FreeAimCam = spawn(newCam,self);
                
                FreeAimCam.FreeCam();
                TPSPlayerCamera it's an extended class from GamePlayerCamera, and i want my function FreeCam() to set an offset to the camera alá: PawnRelativeOffset=(x=0,y=0,z=-25), how can i do this?

                Comment


                • #23
                  i want my function to do a zoom-in behind the weapon and the camera to follow the weapon movement, ironsight style, any idea?

                  im doing this:

                  var TPSPlayerController2 FreeControl ;


                  FreeControl = Spawn(Class'TPSPlayerController2', self);
                  FreeControl.FreeAim();

                  and i have no error while compiling but when i rightclick on the mouse (which activate the function) nothing happens, when i use some function in the same class or in the parent class, they work, but seems that it's not working with functions of other classes.

                  Comment


                  • #24
                    It is probably because the game already has an associated camera that is being used, and has priority over whatever you are doing in FreeAim(). tring to switch between camera actors probably isn't the way to make the view change temporarily. You should set up a couple camera 'states' in a single camera, and switch back and forth between them.

                    Comment


                    • #25
                      thanks blaguuu, you know i just did what lordofduct said and it worked!
                      Code:
                      foreach WorldInfo.DynamicActors(class'MyPlayerControllerClass', PC)
                      {
                           break;//stop looping on the first grab because that's the one we want
                      }
                      
                      Pc.dosomething();
                      you were right and seems like this fix that, cause it looks for the one that you are using, the first one to find and it just worked! thanks!

                      Comment


                      • #26
                        im having right now some issues, when i right-click the mouse the camera starts to follow the pawn movement, but only one time, it doesnt "hold" the movement, i've tried setting the function inside a while sentence , but it freezes the game, any idea?

                        Comment

                        Working...
                        X