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

Is the player crouching?

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

  • Is the player crouching?

    ok, first of all... im somewhat new to unreal coding, but i also am starting to get the overall framework of it. im doing a simple weapon project of my own, mostly to learn how to code a little and also potentially for a mod down the road...

    here's my situation: i want to check to see if the player is crouching, in determining the weapon spread.

    Code:
    event ModeDoFire()
    {
    
        local PlayerController PC;
    
        PC = PlayerController(Instigator.Controller);
    
        // 1. CHECK if GUN IS "COOL"
        if ( Level.TimeSeconds - LastFireTime > 0.5 )
            Spread = Default.Spread;
    
        // 2. CHECK if PLAYER IS CROUCHED
    
        else if ( PC.bIsCrouched == True )
            {
            Log("checking crouch: PC");
            }
    
        // 3. ELSE, WIDEn SPREAD A LOT
    
        else
            {
            Spread = FMin(Spread+0.02,0.12);
            }
    
        LastFireTime = Level.TimeSeconds;
        Super.ModeDoFire();
    }
    yes, i know that code doesnt work

    i was trying to tap into the variable/state by checking the bIsCrouched, but it yells at me ("error, Cast from Pawn to PlayerCOntroller will always fail" is the wotgreal/ucc message).

    how do i do this?

    any/all tips would be greatly appreciated. normally, id look to the base code for a working example of the kind of thing i want, but i just dont see one.

  • #2
    It might help to know what line the compiler is pointing out as containing the error...

    Comment


    • #3
      bIsCrouched is a property of pawn so instead of 'local PlayerControler PC;' you's wand somthing more like 'local Pawn P' i belive 'P = Pawn(instigator);' will work and then you can have 'if (p.bIsCrouched = True)'

      Comment


      • #4
        Originally posted by FireCrack
        bIsCrouched is a property of pawn so instead of 'local PlayerControler PC;' you's wand somthing more like 'local Pawn P' i belive 'P = Pawn(instigator);' will work and then you can have 'if (p.bIsCrouched = True)'
        rgr,. i went ahead and tried that syntax...

        Code:
        event ModeDoFire()
        {
            local Pawn P;
            P = Pawn(instigator); 
        
            // 1. CHECK if GUN IS "COOL"
        
            if ( Level.TimeSeconds - LastFireTime > 0.5 )
                Spread = Default.Spread;
        
            // 2. CHECK if PLAYER IS CROUCHED
        
            else if (p.bIsCrouched = True)
                 {
                 Log("checking crouch: PC");
                 }
        
            // 3. ELSE, WIDEn SPREAD A LOT
        
            else
                {
                Spread = FMin(Spread+0.02,0.12);
                }
        
            LastFireTime = Level.TimeSeconds;
            Super.ModeDoFire();
        }
        the error was: "Cast from 'pawn' to 'Pawn' is unneccessary."

        :bulb:

        Comment


        • #5
          Have you read the error message?

          Instigator is already a pawn. As you are using WOTGreal, you can hold CTRL, point in the word 'instigator' and wait until it gets underlined. When this happens, click on it. You will go to the declaration of the variable (this works for fnctions too). THere you will see something like
          var Pawn Instigator;

          What means that Instigator is of Pawn class. So, you dont need to typecast Instigator to Pawn, as its already one. Generally, you use typecasting to access variables in a child class.

          You should read something about Object Oriented Programming, it will help a lot. The Unreal Wiki have pages about this 2 subjects, OOP and typecasting.

          Good luck

          Comment


          • #6
            Originally posted by luciano.bargman
            Have you read the error message?

            Instigator is already a pawn. As you are using WOTGreal, you can hold CTRL, point in the word 'instigator' and wait until it gets underlined. When this happens, click on it. You will go to the declaration of the variable (this works for fnctions too). THere you will see something like
            var Pawn Instigator;

            What means that Instigator is of Pawn class. So, you dont need to typecast Instigator to Pawn, as its already one. Generally, you use typecasting to access variables in a child class.

            You should read something about Object Oriented Programming, it will help a lot. The Unreal Wiki have pages about this 2 subjects, OOP and typecasting.

            Good luck
            ya, i understand this in concept, just totally new at unreal syntax... and trying anything people suggest.



            I do admit not having much clue about Instigator specifically, although the "controller" rolei think i understand. I'll try some variations. this little excercise is helping me a lot.

            *pokes at code some more*

            PS. i just tried this:

            Code:
                else if ( P.bIsCrouched = true )
                     {
                     Log("checking crouch: PC");
                     }
            and im getting an error about a missing ")"

            P = instigator;

            Comment


            • #7
              else if ( P.bIsCrouched = true )

              should be

              else if ( P.bIsCrouched == true )

              Comment


              • #8
                ahahaha, thanks so much.

                it worked.

                *hides back in his newbie coding cave*

                Comment


                • #9
                  You can also shorten it:
                  else if ( P.bIsCrouched )

                  You don't have to ask if a boolean variable == true.

                  you can use
                  if (!boolean)
                  instead of
                  if (boolean == false)
                  too.

                  Comment

                  Working...
                  X