Announcement

Collapse
No announcement yet.

Ideas on getting "true forward" from FPS camera?

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

    Ideas on getting "true forward" from FPS camera?

    Hello! I have been coding the FPSTutorial (which seems to be the general go-to place for new programmers), and started modifying the control system to better fit my purposes (I'm making a space game). For that I would need the forward to include pitch, which is no found with "FRotator Rotation = Controller->GetControlRotation();". I'm sure many people have and will be wondering this, so I thought I'd post the question here instead of simply digging through to find an answer (which I will proceed to do now), but if someone has already figured this out, please share what you did!
    Thanks, -DoctorPC

    EDIT: upon further inspection of the problem, I have tried to make rotation "tru" by having it as it's separate void. The problem is, I have yet to find "AddMovementInput();"-alternative that would accept rotation. Maybe I need to get it's rotation, and add "value" each tick?
    Last edited by DoctorPC; 09-10-2014, 12:05 AM.

    #2
    GetViewRotation() on the character includes the pitch.

    Comment


      #3
      otherwise great shout, but seems to be that in "FRotator Rotation = Controller->GetViewRotation();" "AController has no member GetViewRotation"

      Comment


        #4
        Yes, Controller does not have that function, but the Character class does.
        I suspect you are calling

        Code:
        FRotator Rotation = Controller->GetViewRotation();
        from your Character class?

        If so, you simply need:

        Code:
        FRotator Rotation = GetViewRotation();

        Comment


          #5
          You could just use the CameraComponent's rotation in world space.

          Inside your character:
          Code:
          FVector ViewDirection = CameraComponent->GetForwardVector()
          or

          Code:
          FRotator Rotation = CameraComponent->GetComponentRotation()

          Comment


            #6
            Hey, it works, almost. I have yet to extract a direction that includes both axis' and I haven't figured it out yet. Here are the two lines so you get what I'm talking about:
            const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
            AddMovementInput(Direction, Value);
            (as you can see, GetScaledAxis(EAxis::X); will filter out the other axis we're getting from GetViewRotation
            Thanks in advance!

            Comment


              #7
              I am not entirely sure what you want to achieve here, so just a few notes:

              The line
              Code:
              const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
              does nothing else but giving you the ForwardVector for the given Rotation - the direction you are facing. X-Axis is the local forward in UE4.

              this line...
              Code:
              const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
              ...on the other hand, would give you the local RightVector in WorldSpace and EAxis::Z the UpVector for the given rotation.

              This is the way to get all 3 axes and you can then use them to translate/rotate your Character/Pawn.

              So if you want to get the local forward vector in WorldSpace, you would use the line you already posted. You can then translate your Pawn along this axis (forwards or backwards)

              Pseudocode:
              Code:
              NewLocation = OldLocation + Direction * OffsetVector
              The AddMovementInput() function just passes this Direction to translate the character using the MovementComponent.

              So you could just proceed the same way for translating Right/Left using the RightVector or RightVector * -1 respectively. The same applies for Up/Down using the UpVector.
              Last edited by DennyR; 09-10-2014, 10:53 AM.

              Comment


                #8
                What I am trying to achieve is that the "W" moves charcter to the "true forward"; so that looking upwards makes the forward be upwards, instead of the "FPS game forward"; which does not take up/down movement into consideration.
                EDIT: Could it be, that these lines do not affect the viewrotation as we would like them to?
                InputComponent->BindAxis("Turn", this, &AMycharacter::AddControllerYawInput);
                InputComponent->BindAxis("LookUp", this, &AMycharacter::AddControllerPitchInput);
                Last edited by DoctorPC; 09-10-2014, 02:17 PM.

                Comment


                  #9
                  Ah, here we go.

                  Does your character use CharacterMovementComponent? If this is the case, then you would have to rewrite some stuff in order to make this work. The basic CharacterMovementComponent uses the XY-Plane for movement and Z for jumping, there is no way around with your input method. You have to go a bit deeper and write your own movement code.

                  You are on the right track. Use the way described above to get the ViewAxes and then apply movement along them per tick based on your input and thats it.

                  THIS 6DOF TUTORIAL might be what you are looking for.

                  Comment


                    #10
                    Any idea where the character controller is located in? (of course I could manually write the movement, but right now I don't feel like trying to figure out the math to have rotation and position, and then change the position according to rotation so that it appears "forward")

                    Comment


                      #11
                      The FPSTutorial doesn't use a special Controller, it handles the input on pawn level, so I am not sure it would help you at all. I don't think there is any way to implement this without writing it yourself.

                      And well, you could just follow the 6DOF tutorial I posted above and be done with it in no time.

                      Comment


                        #12
                        Hey Doc,
                        Ive implemented a similar system into my game, 6dof movement in space with a non physics character, and The playerController doesnt respect the rotations of the character. So youll have to do the same transformations on the characterController that you do on the Character itself. You will also probobly need to modify the CharacterMovementComponent, Rama has a tutorial on the Wiki on how to actually create and use a custom MovementComponent.

                        Comment


                          #13
                          alright, got it done. Thanks so much, cheers!

                          Comment

                          Working...
                          X