Announcement

Collapse
No announcement yet.

Recoil and Zoom limit

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

  • replied
    k i dont know what your doing for the overlays, but i would focus on the functionality of if.

    I would think you need to mess with these functions in the sniperRifle class,
    ClientStartFire(int mode) seems to be when either firemode is pressed, ClientStopFire must be when either firemode is released.

    use these to set the fov if you are just snapping between two fov
    Code:
    var bool bImZoomed;
    
    simulated function ClientStartFire(int mode)
    {
        if (mode == 1)
        {
            FireMode[mode].bIsFiring = true;
            if( Instigator.Controller.IsA( 'PlayerController' ) )
            {
                if(bImZoomed)
                {
                   PlayerController(Instigator.Controller).FOV(90);
                }
                else
                {
                   PlayerController(Instigator.Controller).FOV(40);
                }
            }
        }
        else
        {
            Super.ClientStartFire(mode);
        }
    }
    just do that... it works.

    Leave a comment:


  • replied
    Well first of all i tried doing it and he gives an error upon compiling the code, hmm i copied the code from the sniper rifle and its all a mess, since i dont know my way much around u script although im learning quite fast, i dont know witch functions i need and witch i dont . . need some help here. and thx for answers - the error is ("Bad expression after "=")

    Code:
    //-------------------------------------------------------------------------------------
    //IronSights
    //-------------------------------------------------------------------------------------
    
    simulated event RenderOverlays( Canvas Canvas )
    {
        local int m;
    	local vector NewScale3D;
    	local rotator CenteredRotation;
    	local name AnimSeq;
    	local float frame,rate;
    	local playercontroller PC;
    
    PC=PlayerController( Pawn(Weapon.Owner).Controller ); // get our PC  <--------- problem line !
    
    
        if (Instigator == None)
            return;
    
    	if ( Instigator.Controller != None )
    		Hand = Instigator.Controller.Handedness;
    
        if ((Hand < -1.0) || (Hand > 1.0))
            return;
    
        // draw muzzleflashes/smoke for all fire modes so idle state won't
        // cause emitters to just disappear
        for (m = 0; m < NUM_FIRE_MODES; m++)
        {
            if (FireMode[m] != None)
            {
                FireMode[m].DrawMuzzleFlash(Canvas);
            }
        }
    
    	if ( (OldMesh != None) && (bUseOldWeaponMesh != (OldMesh == Mesh)) )
    	{
    		GetAnimParams(0,AnimSeq,frame,rate);
    		bInitOldMesh = true;
    		if ( bUseOldWeaponMesh )
    			LinkMesh(OldMesh);
    		else
    			LinkMesh(Default.Mesh);
    		PlayAnim(AnimSeq,rate,0.0);
    	}
    
        if ( (Hand != RenderedHand) || bInitOldMesh )
        {
    		newScale3D = Default.DrawScale3D;
    		if ( Hand != 0 )
    			newScale3D.Y *= Hand;
    		SetDrawScale3D(newScale3D);
    		SetDrawScale(Default.DrawScale);
    		CenteredRoll = Default.CenteredRoll;
    		CenteredYaw = Default.CenteredYaw;
    		CenteredOffsetY = Default.CenteredOffsetY;
    		PlayerViewPivot = Default.PlayerViewPivot;
    		SmallViewOffset = Default.SmallViewOffset;
    		if ( SmallViewOffset == vect(0,0,0) )
    			SmallViewOffset = Default.PlayerviewOffset;
    		bInitOldMesh = false;
    		if ( Default.SmallEffectOffset == vect(0,0,0) )
    			SmallEffectOffset = EffectOffset + Default.PlayerViewOffset - SmallViewOffset;
    		else
    			SmallEffectOffset = Default.SmallEffectOffset;
    		if ( Mesh == OldMesh )
    		{
    			SmallEffectOffset = EffectOffset + OldPlayerViewOffset - OldSmallViewOffset;
    			PlayerViewPivot = OldPlayerViewPivot;
    			SmallViewOffset = OldSmallViewOffset;
    			if ( Hand != 0 )
    			{
    				PlayerViewPivot.Roll *= Hand;
    				PlayerViewPivot.Yaw *= Hand;
    			}
    			CenteredRoll = OldCenteredRoll;
    			CenteredYaw = OldCenteredYaw;
    			CenteredOffsetY = OldCenteredOffsetY;
    			SetDrawScale(OldDrawScale);
    		}
    		else if ( Hand == 0 )
    		{
    			PlayerViewPivot.Roll = Default.PlayerViewPivot.Roll;
    			PlayerViewPivot.Yaw = Default.PlayerViewPivot.Yaw;
    		}
    		else
    		{
    			PlayerViewPivot.Roll = Default.PlayerViewPivot.Roll * Hand;
    			PlayerViewPivot.Yaw = Default.PlayerViewPivot.Yaw * Hand;
    		}
    		RenderedHand = Hand;
    	}
    // Begin New/copied sniper code stuff
    
    //use this for a ghetto toggle functionality
    if(bZoomed) //was toggled on
    {
    bZoomed=false; // turn toggle off
    PC.ResetFOV();
    PlayerViewOffset = IronViewOffset;
    PlayerViewPivot.yaw = 111;
    PlayerViewPivot.Pitch = 250;
    }
      else // was toggled off
    {
    bZoomed=true; // turn toggle on
    SetFOV(40.0); 
    PlayerViewOffset = Default.PlayerViewOffset;
    PlayerViewPivot.yaw = 0;
    PlayerViewPivot.Pitch = 400;
    }
    // Player view offset selection
    
    // the rest of the old stuff
    if ( Hand == 0 )
    		PlayerViewOffset.Y = CenteredOffsetY;
    	else
    		PlayerViewOffset.Y *= Hand;
    
        SetLocation( Instigator.Location + Instigator.CalcDrawOffset(self) );
        if ( Hand == 0 )
        {
    		CenteredRotation = Instigator.GetViewRotation();
    		CenteredRotation.Yaw += CenteredYaw;
    		CenteredRotation.Roll = CenteredRoll;
    	    SetRotation(CenteredRotation);
        }
        else
    	    SetRotation( Instigator.GetViewRotation() );
    
    	PreDrawFPWeapon();	// Laurent -- Hook to override things before render (like rotation if using a staticmesh)
    
        bDrawingFirstPerson = true;
        Canvas.DrawActor(self, false, false, DisplayFOV);
        bDrawingFirstPerson = false;
    	if ( Hand == 0 )
    		PlayerViewOffset.Y = 0;
    }
    
    simulated function ClientStartFire(int mode)
    {
        if (mode == 1)
        {
            FireMode[mode].bIsFiring = true;
            if( Instigator.Controller.IsA( 'PlayerController' ) )
                PlayerController(Instigator.Controller).ToggleZoom();
        }
        else
        {
            Super.ClientStartFire(mode);
        }
    }
    
    simulated function ClientStopFire(int mode)
    {
        if (mode == 1)
        {
            FireMode[mode].bIsFiring = false;
            if( PlayerController(Instigator.Controller) != None )
                PlayerController(Instigator.Controller).StopZoom();
        }
        else
        {
            Super.ClientStopFire(mode);
        }
    }
    
    simulated function bool PutDown()
    {
        if( Instigator.Controller.IsA( 'PlayerController' ) )
            PlayerController(Instigator.Controller).EndZoom();
        if ( Super.PutDown() )
    		return true;
    	return false;
    }
    I marked the line that dosent compile and i would really appreciate if u could point out those stuff that can be removed like the old meshes and old viewpoints an ect . . thanks (:

    Leave a comment:


  • replied
    Well that code looks like how you actually change the Field of View, but you want to find what controls the Zooming functionality.

    You should look at the alt fire code of the sniper rifle, if you want it to snap to a certain FOV. it might be in the sniperAltFire Class, but i'll bet its actually handled in the sniperWeapon Class. look for an alt fire function, see if it calls any other functions or gotoStates.

    otherwise it looks like DesiredFOV or FOVAngle of the player controller is the actual power behind it all. you might want to experiment with that and make an alt fire function that just flips inbetween two FOVs.

    put this in your sniper rifles Weapon Class, or put it in the actual AltFire Class of the weapon.

    Code:
    var bool bZoomedIn; // this needs to be a global variable, put just below class definition.
    
    function AltFire()
    {
    local playercontroller PC;
    
    Super.AltFire(); //might need this actually
    
    PC=PlayerController( Pawn(Weapon.Owner).Controller ); // get our PC
    
    //use this for a ghetto toggle functionality
      if(bZoomedIn) //was toggled on
    {
    bZoomedIn=false; // turn toggle off
    PC.ResetFOV();
    }
      else // was toggled off
    {
    bZoomedIn=true; // turn toggle on
    SetFOV(40.0); 
    }
    
    }
    
    
    bZoomedIn=false // put this in your defaultproperties at the bottom
    im not sure if that will work.
    if it doesnt work in game open the console with ' ~ '
    the type in ' FOV 130 ' and press enter. if that does nothing than ... give up! lol just kidding.

    i dont know if you know this, but those ' exec ' functions defined in player controller class can be activated in game via the console, just type the name of the function, then type the parameters. i only recently found that out and it has been so helpful in testing my mod.

    anyways good luck, tell me if that doesnt work.

    Leave a comment:


  • replied
    Thank you it works great !!

    thanks again and heres the zoom codes u requested

    The zoom stuff from player controller - (might be more not sure)

    Code:
    // ------------------------------------------------------------------------
    // Zooming/FOV change functions
    
    function ToggleZoomWithMax(float MaxZoomLevel)
    {
        if ( DefaultFOV != DesiredFOV )
            EndZoom();
        else
    		StartZoomWithMax(MaxZoomLevel);
    }
    
    function StartZoomWithMax(float MaxZoomLevel)
    {
    	DesiredZoomLevel = MaxZoomLevel;
    	myHUD.FadeZoom();
        ZoomLevel = 0.0;
        bZooming = true;
    }
    
    function ToggleZoom()
    {
    	ToggleZoomWithMax(0.9);
    }
    
    function StartZoom()
    {
    	StartZoomWithMax(0.9);
    }
    
    function StopZoom()
    {
        bZooming = false;
    }
    
    function EndZoom()
    {
    	if ( DesiredFOV != DefaultFOV )
    		myHUD.FadeZoom();
        bZooming = false;
        DesiredFOV = DefaultFOV;
    }
    
    simulated function FixFOV()
    {
    	FOVAngle = Default.DefaultFOV;
        DesiredFOV = Default.DefaultFOV;
        DefaultFOV = Default.DefaultFOV;
    }
    
    function SetFOV(float NewFOV)
    {
        DesiredFOV = NewFOV;
        FOVAngle = NewFOV;
    }
    
    function ResetFOV()
    {
        DesiredFOV = DefaultFOV;
    	FOVAngle = DefaultFOV;
    }
    
    exec function FOV(float F)
    {
        if( (F >= 80.0) || (Level.Netmode==NM_Standalone) || PlayerReplicationInfo.bOnlySpectator )
        {
            DefaultFOV = FClamp(F, 1, 170);
            DesiredFOV = DefaultFOV;
            SaveConfig();
        }
    }
    And usage in the classic sniper rifle

    Code:
    simulated event RenderOverlays( Canvas Canvas )
    {
    	local float CX,CY,Scale;
    	local float chargeBar;
    	local float barOrgX, barOrgY;
    	local float barSizeX, barSizeY;
    
    	if ( PlayerController(Instigator.Controller) == None )
    	{
            Super.RenderOverlays(Canvas);
    		zoomed=false;
    		return;
    	}
    
        if ( LastFOV > PlayerController(Instigator.Controller).DesiredFOV )
        {
            PlaySound(Sound'WeaponSounds.LightningGun.LightningZoomIn', SLOT_Misc,,,,,false);
        }
        else if ( LastFOV < PlayerController(Instigator.Controller).DesiredFOV )
        {
            PlaySound(Sound'WeaponSounds.LightningGun.LightningZoomOut', SLOT_Misc,,,,,false);
        }
        LastFOV = PlayerController(Instigator.Controller).DesiredFOV;
    
        if ( PlayerController(Instigator.Controller).DesiredFOV == PlayerController(Instigator.Controller).DefaultFOV )
    	{
            Super.RenderOverlays(Canvas);
    		zoomed=false;
    	}
    	else
        {
    		if ( FireMode[0].NextFireTime <= Level.TimeSeconds )
    		{
    			chargeBar = 1.0;
    		}
    		else
    		{
    			chargeBar = 1.0 - ((FireMode[0].NextFireTime-Level.TimeSeconds) / FireMode[0].FireRate);
    		}
    
    		CX = Canvas.ClipX/2;
    		CY = Canvas.ClipY/2;
    		Scale = Canvas.ClipX/1024;
    
    		Canvas.Style = ERenderStyle.STY_Alpha;
    		Canvas.SetDrawColor(0,0,0);
    
    		// Draw the crosshair
    		Canvas.SetPos(CX-169*Scale,CY-155*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',169*Scale,310*Scale, 164,35, 169,310);
    		Canvas.SetPos(CX,CY-155*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',169*Scale,310*Scale, 332,345, -169,-310);
    
    		// Draw Cornerbars
    		Canvas.SetPos(160*Scale,160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 111*Scale, 111*Scale , 0 , 0, 111, 111);
    
    		Canvas.SetPos(Canvas.ClipX-271*Scale,160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 111*Scale, 111*Scale , 111 , 0, -111, 111);
    
    		Canvas.SetPos(160*Scale,Canvas.ClipY-271*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 111*Scale, 111*Scale, 0 , 111, 111, -111);
    
    		Canvas.SetPos(Canvas.ClipX-271*Scale,Canvas.ClipY-271*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 111*Scale, 111*Scale , 111 , 111, -111, -111);
    
    
    		// Draw the 4 corners
    		Canvas.SetPos(0,0);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',160*Scale,160*Scale, 0, 274, 159, -158);
    
    		Canvas.SetPos(Canvas.ClipX-160*Scale,0);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',160*Scale,160*Scale, 159,274, -159, -158);
    
    		Canvas.SetPos(0,Canvas.ClipY-160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',160*Scale,160*Scale, 0,116, 159, 158);
    
    		Canvas.SetPos(Canvas.ClipX-160*Scale,Canvas.ClipY-160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair',160*Scale,160*Scale, 159, 116, -159, 158);
    
    		// Draw the Horz Borders
    		Canvas.SetPos(160*Scale,0);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', Canvas.ClipX-320*Scale, 160*Scale, 284, 512, 32, -160);
    
    		Canvas.SetPos(160*Scale,Canvas.ClipY-160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', Canvas.ClipX-320*Scale, 160*Scale, 284, 352, 32, 160);
    
    		// Draw the Vert Borders
    		Canvas.SetPos(0,160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 160*Scale, Canvas.ClipY-320*Scale, 0,308, 160,32);
    
    		Canvas.SetPos(Canvas.ClipX-160*Scale,160*Scale);
    		Canvas.DrawTile(texture'NewSniperRifle.COGAssaultZoomedCrosshair', 160*Scale, Canvas.ClipY-320*Scale, 160,308, -160,32);
    
    		// Draw the Charging meter
    		Canvas.DrawColor = ChargeColor;
            Canvas.DrawColor.A = 255;
    
    		if(chargeBar <1)
    		    Canvas.DrawColor.R = 255*chargeBar;
    		else
            {
                Canvas.DrawColor.R = 0;
    		    Canvas.DrawColor.B = 0;
            }
    
    		if(chargeBar == 1)
    		    Canvas.DrawColor.G = 255;
    		else
    		    Canvas.DrawColor.G = 0;
    
    		Canvas.Style = ERenderStyle.STY_Alpha;
    		Canvas.SetPos( barOrgX, barOrgY );
    		Canvas.DrawTile(Texture'Engine.WhiteTexture',barSizeX,barSizeY*chargeBar, 0.0, 0.0,Texture'Engine.WhiteTexture'.USize,Texture'Engine.WhiteTexture'.VSize*chargeBar);
    		zoomed = true;
    	}
    }

    Leave a comment:


  • replied
    i did the recoil once, you have to access the weapons owner which should be a pawn, then access the pawns playercontroller class, and then finally do the set rotation.

    the thing you need to know is that SetRotation is a function that i believe was defined in actor class. so what ever you want to rotate needs to be like this
    ( Actor.SetRotation(Rotator R); ) obviously replace actor with what you want to rotate, and replace R with a rotator of the desired rotation.

    im not sure if this is exactly how you would do this, but here it is.

    put this in your fire or fireeffect function of your weapon
    Code:
    local PlayerController PC;
    local rotator r;
    
        //not sure if this is exactly how you get the player controller.
    PC=PlayerController( Pawn(Weapon.Owner).Controller )
        //get weapons owner, typecast to pawn, get pawn controller, typecast to player controller.
    
    if(PC!=None) // if after all typecasting we actually have a playercontroller
    {
       r=PC.Rotation; //grab current rotation
       r.Pitch+=200; //increase pitch by a bit
       PC.SetRotation(r); //set the rotation of PC to new rotation
    }
    about the zoom, all camera effects are controlled by the playercontroller. look for a reference to the player controller class in the alt fire code of the sniper rifle. post it here if you can, ive never messed with zooming before.

    Leave a comment:


  • started a topic Recoil and Zoom limit

    Recoil and Zoom limit

    Hey all i got 2 questions that i have some problems with.

    First one is recoil, i have seen a thread about it here that says to find a "setrotation" function in playercontroller but i was unablw to find a function named exactly that,many many functions with "Rotation" in them i just want with every click my gun to raise up abit, so how do i write this ?

    And 2nd is the zoom limit, iw as surprised to find out that this zooming function the sniper rifle's use is taken from playrercontroller . . so i created a weapon with a iron sight alt fire (base code taken from sniper rifle) and now if i hold the button it zoom's like a sniper rifle and i want with one click to dispaly a certain FOV and not react to a holded down button.

    Thx everyone
Working...
X