Announcement

Collapse
No announcement yet.

Working with device orientation

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

    Working with device orientation

    I basically want to take the orientation of my phone and use that as one to one input for my player pawn's aiming direction in game. I've done this before outside unreal by just reading the device orientation matrices on ios and android, but it's not as obvious in Unreal how to do that.

    I see there are inputs for Tilt, Gravity, Rotation Rate, and Acceleration. How would I go about binding those and using them in C++? As far as I know, C++ works with floats for axis bindings. And in blueprint I see events for Tilt but for the other events I only see getters.

    #2
    You can set the device rotation as an axis under the project settings/input section. At least, I have done this in iOS. If you have an axis already in place, just add rotation in the mobile section when adding a new input. This bound the device's rotation to that axis, allowing me to rotate a camera via the on device gyro. I'll try to remember to add a screenshot tomorrow.

    Hope this helps...

    Cheers,

    J^2
    This is a thing that is cool: Zeustiak's Map Generator 3.0

    Everyone should be using: Rama's Epic Blueprint Plugin Package!

    Comment


      #3
      Oh nice. I must have not seen device rotation itself. It'll save me quite a bit of work if I don't have to manually derive it from gravity, and rotation rate, and whatever tilt means. I'll have to look for that tonight after my day job.

      Comment


        #4
        Found it!

        OK, found it.

        Click image for larger version

Name:	Screen Shot 2015-03-12 at 5.16.35 PM.png
Views:	1
Size:	47.6 KB
ID:	1068319

        When adding a new axis mapping, at the very bottom of the keyboard section (which makes sense right), there are several touch inputs. Map rotation rate to get the gyro input. At least, this is working for me on iOS. Hope this helps. Cheers,

        J^2
        This is a thing that is cool: Zeustiak's Map Generator 3.0

        Everyone should be using: Rama's Epic Blueprint Plugin Package!

        Comment


          #5
          Oh yeah I did see rotation rate. I assumed it was raw and I had to derive it from combining it with gravity and tilt or something like on Android if doing it with raw API's. I'll see if I get good results from this.

          Got it working! It works really well. When I was doing this myself on android I had really jittery input or really bad lag from trying to filter the input. I'm not sure how Unreal does it, but it feels almost as good as an iPhone's gyro input. Although when I set my phone flat on the table or hold it in my hands without moving it still moves a bit which is dissapointing. Iphones definitely always had better gyros.

          Anyway, in C++ I had to call InputComponent->BindVectorAxis("RotationRate", this, &AODPlayerTurret::OnRotationInput);

          That was the way to get rotation rate as a bindable input.
          Last edited by illYay; 03-13-2015, 12:22 AM.

          Comment


            #6
            Good to hear! Cheers,

            J^2
            This is a thing that is cool: Zeustiak's Map Generator 3.0

            Everyone should be using: Rama's Epic Blueprint Plugin Package!

            Comment


              #7
              Hi JJ,

              Thanks for the screen shot. On an iPad 4 and on 4.7.2, I start with a basic scene. table and chairs. Add those Axis inputs as per your screenshot and nothing once it's on my device. Is there some BP that's got to go on with those nodes? I see them but have no idea what to plug them into.

              Comment


                #8
                Well...

                Well, I'm most likely the worst possible person to be answering this, but here goes. After mapping the input, you then have to do something with it. So, if you have a camera that you want to rotate, then you would make a blueprint that uses the proper InputAxis node (the one that matches the name of the input axis you created in the project settings) to trigger the camera to move. Here's a grab of the blueprint I am using, which is built from Monokkel's wonderful TBS toolkit:

                Click image for larger version

Name:	Screen Shot 2015-03-16 at 12.56.02 AM.png
Views:	1
Size:	154.7 KB
ID:	1070419

                The spring arm that is getting the input rotation added to it is the focal point of the camera in my case. I hope this helps get you started. I'd strongly recommend going through the getting input via blueprint tutorials though. It will be a much stronger base to build from then anything I could offer. Good luck! Cheers,

                J^2
                This is a thing that is cool: Zeustiak's Map Generator 3.0

                Everyone should be using: Rama's Epic Blueprint Plugin Package!

                Comment


                  #9
                  Here's how I'm doing it in C++ for now. I think I still need to take gravity into account. There's some random motion in there even when the device is standing still.

                  Code:
                  void AODPlayerTurret::SetupPlayerInputComponent(class UInputComponent* InputComponent)
                  {
                  	InputComponent->BindVectorAxis("RotationRate", this, &AODPlayerTurret::OnRotationInput);
                  }
                  
                  void AODPlayerTurret::OnRotationInput(FVector Input)
                  {
                  	static float DEG_TO_RAD = PI / (180.f);
                  		
                  	//TODO: get right and down scale factor from player controller to make the game playable for people who don't want to do full body motions, like while sitting
                  
                  	FQuat RightRot = FQuat(FVector(0.f, 0.f, -1.f), Input.Y * DEG_TO_RAD);		//Why is right reversed, I don't know...  Damnit MATH!!!!
                  	FQuat DownRot = FQuat(FVector(0.f, 1.f, 0.f), Input.X * DEG_TO_RAD);
                  	FQuat RollLeftRot = FQuat(FVector(1.f, 0.f, 0.f), Input.Z * DEG_TO_RAD);
                  	
                  	FQuat Result = GetActorQuat() * RightRot * DownRot * RollLeftRot;
                  
                  	SetActorRotation(Result.Rotator());
                  }

                  Comment


                    #10
                    Seems pretty simple on ios. Don't know about android, but works quite well.

                    Click image for larger version

Name:	VfMOBYb.png
Views:	2
Size:	169.5 KB
ID:	1071228

                    Comment


                      #11
                      I had an idea for a project that would involve something like this but am not a programmer myself. If anyone gets this working I would appreciate anything that could help me integrate it. Tutorial? Template?

                      Comment


                        #12
                        Also very interested in an answer to this

                        Comment


                          #13
                          Any chance that someone has tried this through pixelstreaming? Is it even possible to collect this information through the browser?

                          Comment

                          Working...
                          X