Results 1 to 20 of 20
  1. #1
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default Limiting Camera view rotation

    Hi 2 ALL.

    so i have coded a third person cam using mougli's tutorials , but i want to limit rotation of the camera. it goes like this :

    the player must have rotation boundaries so must the cam , they cant rotate their aim until a certain point . but i cant figure out how to pull this off on either of them ( the pawn & the camera ).
    so figured i'l ask here .

    Codes :

    cam class
    Code:
    class AcCamClass extends GamePlayerCamera;
    
    protected function GameCameraBase FindBestCameraType(Actor CameraTarget)
    {
    	return ThirdPersonCam;
    }
    DefaultProperties
    {
    	ThirdPersonCameraClass=class'Bob.AcThirdPersonCam'
    }
    third person cam

    Code:
    class AcThirdPersonCam extends GameCameraBase;
    
    var float ThirdPersonCamOffsetX;
    var float ThirdPersonCamOffsetY;
    var float ThirdPersonCamOffsetZ;
    var Rotator CurrentCamOrientation;
    var Rotator DesiredCamOrientation;
    var CenterObj CObj;
    var Vector CPos;
    
    simulated function PostBeginPlay()
    {
              Super.PostBeginPlay();
    		  	foreach AllActors(class'Bob.CenterObj',CObj)
    	{
    		CPos = CObj.Location;
    	}
    
    }
    function UpdateCamera(Pawn P, GamePlayerCamera CameraActor, float DeltaTime, out TViewTarget OutVT)
    {
        local float Radius, Height;
        local vector X,Y,Z;
    
        P.GetAxes(DesiredCamOrientation,X,Y,Z); // We will be working with coordinates in pawn space, but rotated according to the Desired Rotation.
    
        P.GetBoundingCylinder(Radius, Height); //Get the pawn's height as a base for the Z offset.
    	
        OutVT.POV.Location = P.Location + ThirdPersonCamOffsetX * X + ThirdPersonCamOffsetY * Y + (Height+ThirdPersonCamOffsetZ) * Z;
    
        if (DesiredCamOrientation != CurrentCamOrientation)
        {
    	CurrentCamOrientation = RInterpTo(CurrentCamOrientation,DesiredCamOrientation,DeltaTime,10);
        }
        OutVT.POV.Rotation = CurrentCamOrientation;
    }
    
    function ProcessViewRotation( float DeltaTime, Actor ViewTarget, out Rotator out_ViewRotation, out Rotator out_DeltaRot )
    {
    	DesiredCamOrientation = out_ViewRotation + out_DeltaRot;
    }
    
    DefaultProperties
    {
        ThirdPersonCamOffsetX=-80.0
        ThirdPersonCamOffsetY=8.0
        ThirdPersonCamOffsetZ=-32.0
    }
    there's nothing special about the pawn so i didnt post it here but feel free to ask.
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  2. #2
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    Wow not even a "your Question is noob" ?
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  3. #3
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    that wouldn't be very nice now would it?

    how should we think of the boundaries? are they relative to something, or absolute?
    Last edited by thommie; 05-15-2012 at 03:06 PM.

  4. #4
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    well actually its related to this "complicated" thing...

    the player ( owner of the camera and the pawn ) is actually a gunship plane that rotates around an object called the centerObj . so the actual max and min rotations are changing (speaking in terms of raw vector math) but if there is a general way to do i , it wont really matter.
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  5. #5
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    if i'm correct in understanding, the rotation limit depends on either the gunship plane (the pawn) or the centerObj. if you have a reference to either, lets say Ref it shouldn't be too hard.

    for each of the rotator's element you could use FClamp() before you check if the DesiredCamOrientation differs from the CurrentCamOrientation.

    the limit is how much the camera's rotation can differ from the Ref's rotation, that part is up to you and ranges from 0 - 65536;

    Code:
    local Vector Limit;
    DesiredCamOrientation.Pitch = Fclamp(DesiredCamOrientation.Pitch, Ref.Rotation.Pitch - Limit.Pitch,Ref.Rotation.Pitch + Limit.Pitch);
    DesiredCamOrientation.Yaw = etc...
    i hope this helps.

  6. #6
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    well thanks thommie i'l try that out but let me clarify the situation further :

    the gunship rotating around the center object will be looking at the center object ( center object is on the ground but the gunship is rotation it airborn in a cone like pattern) . meaning our view focus must be the center object and the limits must be set according to it. the view rotation is not limited around a specific area around the centerObj . the limitations are implemented as if we were looking directly at the center obj with rotation vector R , then the limits (for that position ) would be R+limit & R-limit.

    that suggestion thommie might just work , i thought i just clarify the subject a bit further
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  7. #7
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    i was never any good with rotators, but i know that i misunderstood your situation so my previous suggestion will fail.

    It will take some trying since i knew how to do it in the past, so i'm confident i should be able to give you a solution.

  8. #8
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    i was out trying to test your solution and well , I'm very confused !
    see the third person cam extends off GameCameraBase and that's what holding the rotations and stuff. it doesn't have any postbeginplay and stuff. and I have no idea how to determine the limit vector
    also what does Clamp do ?
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  9. #9
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    float FClamp (float V, float A, float B) [static]
    If V is smaller than A, A is returned. If V is larger than B, B is returned. In any other case V is returned.

    in my example, which is useless to you, the limit could be set in the defaultproperties.

  10. #10
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    it was as i had suspected

    Code:
    simulated event GetPlayerViewPoint( out vector POVLocation, out Rotator POVRotation )
    {
    	super.GetPlayerViewPoint(POVLocation,POVRotation);
    	POVRotation = Rotator(Vect(0,0,0) - POVLocation);
    }
    i tried focusing my camera on location (0,0,0) like this, and it worked. (didn't feel the need to create a camera class, so i did it from the playercontroller, doesn't really matter)

    so in your case it would be something like
    Code:
    OutVT.POV.Rotation = Rotator(Ref.Location - OutVT.POV.Location);
    where Ref is the reference to the center object, at least make sure you have a reference to the location of that object.

    good luck, and i hope this solves it

  11. #11
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Use ClampRotAxisFromRange...

  12. #12
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    ok vendorX but.... i'm a noob could you give me an example ?
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  13. #13
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    @Thommie it didnt work (

    see the equivalent function at cameras is Get camera view point and cant be overridden because its a "final" function. also i dont get the whole logic behind the solution looks a bit off anyways thanks for the help looking for further help.
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  14. #14
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    First do all standard calculations, then at the end call ClampRotAxisFromRange for Pitch, Yaw and Roll - you can define different Min/Max for each...
    i.e.
    Code:
    //...
    OutVT.POV.Rotation.Pitch = ClampRotAxisFromRange(CurrentCamOrientation.Pitch, Min, Max);
    OutVT.POV.Rotation.Yaw = ClampRotAxisFromRange(CurrentCamOrientation.Yaw, Min, Max);
    OutVT.POV.Rotation.Roll = ClampRotAxisFromRange(CurrentCamOrientation.Roll, Min, Max);
    //...
    ...remove unwanted...

  15. #15
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    Quote Originally Posted by VendorX View Post
    First do all standard calculations, then at the end call ClampRotAxisFromRange for Pitch, Yaw and Roll - you can define different Min/Max for each...
    i.e.
    Code:
    //...
    OutVT.POV.Rotation.Pitch = ClampRotAxisFromRange(CurrentCamOrientation.Pitch, Min, Max);
    OutVT.POV.Rotation.Yaw = ClampRotAxisFromRange(CurrentCamOrientation.Yaw, Min, Max);
    OutVT.POV.Rotation.Roll = ClampRotAxisFromRange(CurrentCamOrientation.Roll, Min, Max);
    //...
    ...remove unwanted...
    yeah thanks dude but i dot think that will work because first of all my cam will be focused on a center object and will be moving around it in a circular fashion so the so called "Default" rotation vector will be constantly changing so the min and max will be changing and i'm only a highschool student so its hard for me to work out the math on how the min max would change .
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  16. #16
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    you know i had this idea earlier i wanted to know if the math is correct :

    OutVT.POV.Rotation.Pitch = ClampRotAxisFromRange(CObj.location.X - Self.Location.X , Min, Max);

    where self is the player controller.
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  17. #17
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Before calling ClampRotAxisFromRange add Base rotation to Min and Max.

  18. #18
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Posts
    453

    Default

    thanks VendorX and THommie ! i've almost completed the system i needed ! just a little problem

    see when i clamp the yaw , it suddenly snaps to another yaw and stays there. this is highly unwanted guys , help me out here .

    The current code is in player controller and dealing with the POV.

    Code:
    DefVector = Rotator(Vect(0,0,0)-POVLocation);
    POVRotation.Yaw = ClampRotAxisFromRange(POVRotation.Yaw,DefVector.Yaw+30000,DefVector.Yaw+60000);
    I 4M 4LW4Y5 H3LPFUL. 4T L345T ! BuMp3D Y0uR THr34D.

  19. #19
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    901

    Default

    it seems to me you have set some weird range, but i suppose you have a reason for it.

    you could try displaying all those three values on the HUD so you can see where it is going wrong (so you should comment the ClampRotAxisFromRange line else it will fail).

  20. #20
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Yeah, this range is cover only the left side of POV - should be -/+.


    Quote Originally Posted by U F O View Post
    ...
    see when i clamp the yaw , it suddenly snaps to another yaw and stays there...
    Probably because of NormalizeRotAxis (it transform to -32768/+32767 range...) - copy whole ClampRotAxisFromRange (is final, you can't override...), rename and remove normalisation.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.