prevent bunnyhopping ==> timer between jumps?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

ZitherMan

New Member
Oct 11, 2001
24
0
0
Ok, I'm making this mod where bunnyhopping shouldnt be allowed. I'm thinking about adding a timer between the jumps and while that timer is below 0.5 seconds (or something) bCanJump should be false. So i went ahead and thought, i'll start the timer when the person have landed. I found this code in TournamentPlayer:

Code:
function PlayLanded(float impactVel)
{	
	impactVel = impactVel/JumpZ;
	impactVel = 0.1 * impactVel * impactVel;
	BaseEyeHeight = Default.BaseEyeHeight;

	if ( impactVel > 0.17 )
		PlayOwnedSound(LandGrunt, SLOT_Talk, FMin(5, 5 * impactVel),false,1200,FRand()*0.4+0.8);
	if ( !FootRegion.Zone.bWaterZone && (impactVel > 0.01) )
		PlayOwnedSound(Land, SLOT_Interact, FClamp(4 * impactVel,0.5,5), false,1000, 1.0);
	if ( (impactVel > 0.06) || (GetAnimGroup(AnimSequence) == 'Jumping') || (GetAnimGroup(AnimSequence) == 'Ducking') )
	{
		if ( (Weapon == None) || (Weapon.Mass < 20) )
			TweenAnim('LandSMFR', 0.12);
		else
			TweenAnim('LandLGFR', 0.12);
	}
	else if ( !IsAnimating() )
	{
		if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
		{
			SetPhysics(PHYS_Walking);
			AnimEnd();
		}
		else 
		{
			if ( (Weapon == None) || (Weapon.Mass < 20) )
				TweenAnim('LandSMFR', 0.12);
			else
				TweenAnim('LandLGFR', 0.12);
		}
	}
}

So I'll overrun this in my own playerclass, i'll just copy everything. Now then, how do i add a timer like this and how do i check if it did jump and didnt just fall down a step? Is there any1 out there who can help me?
 

Papapishu

我是康
Jun 18, 2001
2,043
0
0
43
void
www.vovoid.com
when he lands, call:

pawn.bCanJump=false;
settimer(2,false);


and in timer:

function timer()
{
pawn.bCanJump=true;
}

be sure to make sure that the timer function isn't already taken for some purpose.
if it is, you might make a new state like this:
when landing:

gotostate("ledfoot");

...

state ledfoot
{
function timer()
{
pawn.bCanJump=true;
}

function beginstate()
{
pawn.bCanJump=false;
settimer(2,false);
}

get it?
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
thank you for that, but i dont think i've understood exactly since it doesnt work the way i want to. When i have jumped once, the character lands and then he begin to float the direction you were flying. You cant stop him, you cant look around. You can only shoot.
This is my current code:

Code:
class testplayer extends TournamentMale;

function PlayLanded(float impactVel)
{	
	impactVel = impactVel/JumpZ;
	impactVel = 0.1 * impactVel * impactVel;
	BaseEyeHeight = Default.BaseEyeHeight;

	if ( impactVel > 0.17 )
		PlayOwnedSound(LandGrunt, SLOT_Talk, FMin(5, 5 * impactVel),false,1200,FRand()*0.4+0.8);
	if ( !FootRegion.Zone.bWaterZone && (impactVel > 0.01) )
		PlayOwnedSound(Land, SLOT_Interact, FClamp(4 * impactVel,0.5,5), false,1000, 1.0);
	if ( (impactVel > 0.06) || (GetAnimGroup(AnimSequence) == 'Jumping') || (GetAnimGroup(AnimSequence) == 'Ducking') )
	{
		if ( (Weapon == None) || (Weapon.Mass < 20) )
		{
			TweenAnim('LandSMFR', 0.12);
			gotostate('ledfoot');
		}
		else
		{
			TweenAnim('LandLGFR', 0.12);
			gotostate('ledfoot');
		}
	}
	else if ( !IsAnimating() )
	{
		if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
		{
			SetPhysics(PHYS_Walking);
			AnimEnd();
			gotostate('ledfoot');
		}
		else 
		{
			if ( (Weapon == None) || (Weapon.Mass < 20) )
			{
				TweenAnim('LandSMFR', 0.12);
				gotostate('ledfoot');
			}
			else
			{
				TweenAnim('LandLGFR', 0.12);
				gotostate('ledfoot');
			}
		}
	}
}


state ledfoot 
{ 
	function timer() 
	{ 
		bCanJump=true;
	} 
	
	function beginstate() 
	{ 
		bCanJump=false; 
		settimer(0.5,false); 
	} 

}

defaultproperties
{
	JumpZ=200
     FaceSkin=3
     FixedSkin=2
     TeamSkin2=1
     DefaultSkinName="SoldierSkins.blkt"
     DefaultPackage="SoldierSkins."
     LandGrunt=Sound'Botpack.MaleSounds.(All).land10'
     CarcassType=Class'Botpack.TMale2Carcass'
     SelectionMesh="Botpack.SelectionMale2"
     SpecialMesh="Botpack.TrophyMale2"
     MenuName="Nisse"
     VoiceType="BotPack.VoiceMaleTwo"
     Mesh=LodMesh'Botpack.Soldier'
}
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
hmmm
what is the normal state called?
I havnt added any normal state to my code. Is there one in any parent class?

It now looks like this:

Code:
state ledfoot 
{ 
	function timer() 
	{ 
		bCanJump=true;
		gotostate('normalstate');
	} 
	
	function beginstate() 
	{ 
		bCanJump=false; 
		settimer(0.5,false); 
	}
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
Ok, i've fixed that thing now. It still doesnt work the way i want to tho. When the player has landed it floats for 2 secs the way you jumped and then you can control it again. I want to be able to control it but not being able to jump. The code now is:

Code:
state ledfoot 
{ 
	function timer() 
	{ 
		bCanJump=true;
		GoToState('PlayerWalking');
	} 
	
	function beginstate() 
	{ 
		bCanJump=false; 
		settimer(0.5,false); 
	} 

}

Anybody got any suggestions?
 

Mychaeel

New Member
Putting the PlayerPawn in a different state ("ledfoot" in your case) impairs normal movement during that time.

The "PlayerWalking" state in PlayerPawn doesn't use a timer. I suggest you scratch that "ledfoot" state and just implement your timer in the "PlayerWalking" state.
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
ok, i did as you said. But now it aint working at all.
What i did was, i made a new bool (bAntiBunnyHopping). And set it to true every time you land. Then in the playerwalking state i put
Code:
if(bAntiBunnyHopping)
{
	bCanJump=false;
	settimer(2,false);
}
.
In top of the playerwalking state i put:
Code:
function timer()
{
	bCanJump=true;
	bAntiBunnyHopping=False;
}

But the bAntiBunnyHopping never turns false again. So i guess it doesnt do the timer thing.
Do you know what might be the error?
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
well, it still dont work...
i'll post the full code here (changed parts in red):
Code:
class testplayer extends TournamentMale;

[COLOR=red]
var bool bAntiBunnyHopping;
var int NoJumpingTime;
[/COLOR]

function PlayLanded(float impactVel)
{	
	impactVel = impactVel/JumpZ;
	impactVel = 0.1 * impactVel * impactVel;
	BaseEyeHeight = Default.BaseEyeHeight;

	if ( impactVel > 0.17 )
		PlayOwnedSound(LandGrunt, SLOT_Talk, FMin(5, 5 * impactVel),false,1200,FRand()*0.4+0.8);
	if ( !FootRegion.Zone.bWaterZone && (impactVel > 0.01) )
		PlayOwnedSound(Land, SLOT_Interact, FClamp(4 * impactVel,0.5,5), false,1000, 1.0);
	if ( (impactVel > 0.06) || (GetAnimGroup(AnimSequence) == 'Jumping') || (GetAnimGroup(AnimSequence) == 'Ducking') )
	{
		if ( (Weapon == None) || (Weapon.Mass < 20) )
		{
			TweenAnim('LandSMFR', 0.12);
			[COLOR=red]bAntiBunnyHopping=False;[/COLOR]
		}
		else
		{
			TweenAnim('LandLGFR', 0.12);
			[COLOR=red]bAntiBunnyHopping=False;[/COLOR]
		}
	}
	else if ( !IsAnimating() )
	{
		if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
		{
			SetPhysics(PHYS_Walking);
			AnimEnd();
			[COLOR=red]bAntiBunnyHopping=False;[/COLOR]
		}
		else 
		{
			if ( (Weapon == None) || (Weapon.Mass < 20) )
			{
				TweenAnim('LandSMFR', 0.12);
				[COLOR=red]bAntiBunnyHopping=False;[/COLOR]
			}
			else
			{
				TweenAnim('LandLGFR', 0.12);
				[COLOR=red]bAntiBunnyHopping=False;[/COLOR]
			}
		}
	}
}


state PlayerWalking
{
ignores SeePlayer, HearNoise, Bump;

	[COLOR=red]function Timer()
	{
		if(!bAntiBunnyHopping)
		{
			bCanJump=true;
			bAntiBunnyHopping=true;
		}
		Disable('Timer');
	}[/COLOR]

	exec function FeignDeath()
	{
		if ( Physics == PHYS_Walking )
		{
			ServerFeignDeath();
			Acceleration = vect(0,0,0);
			GotoState('FeigningDeath');
		}
	}

	function ServerFeignDeath()
	{
		local Weapon W;

		W = Weapon;
		PendingWeapon = None;
		if ( Weapon != None )
			Weapon.PutDown();
		PendingWeapon = W;
		GotoState('FeigningDeath');
	}

	function ZoneChange( ZoneInfo NewZone )
	{
		if (NewZone.bWaterZone)
		{
			setPhysics(PHYS_Swimming);
			GotoState('PlayerSwimming');
		}
	}

	function AnimEnd()
	{
		local name MyAnimGroup;

		bAnimTransition = false;
		if (Physics == PHYS_Walking)
		{
			if (bIsCrouching)
			{
				if ( !bIsTurning && ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000) )
					PlayDuck();	
				else
					PlayCrawling();
			}
			else
			{
				MyAnimGroup = GetAnimGroup(AnimSequence);
				if ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000)
				{
					if ( MyAnimGroup == 'Waiting' )
						PlayWaiting();
					else
					{
						bAnimTransition = true;
						TweenToWaiting(0.2);
					}
				}	
				else if (bIsWalking)
				{
					if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit')  )
					{
						TweenToWalking(0.1);
						bAnimTransition = true;
					}
					else 
						PlayWalking();
				}
				else
				{
					if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit')  )
					{
						bAnimTransition = true;
						TweenToRunning(0.1);
					}
					else
						PlayRunning();
				}
			}
		}
		else
			PlayInAir();
	}

	function Landed(vector HitNormal)
	{
		Global.Landed(HitNormal);
		if (DodgeDir == DODGE_Active)
		{
			DodgeDir = DODGE_Done;
			DodgeClickTimer = 0.0;
			Velocity *= 0.1;
		}
		else
			DodgeDir = DODGE_None;
	}

	function Dodge(eDodgeDir DodgeMove)
	{
		local vector X,Y,Z;

		if ( bIsCrouching || (Physics != PHYS_Walking) )
			return;

		GetAxes(Rotation,X,Y,Z);
		if (DodgeMove == DODGE_Forward)
			Velocity = 1.5*GroundSpeed*X + (Velocity Dot Y)*Y;
		else if (DodgeMove == DODGE_Back)
			Velocity = -1.5*GroundSpeed*X + (Velocity Dot Y)*Y; 
		else if (DodgeMove == DODGE_Left)
			Velocity = 1.5*GroundSpeed*Y + (Velocity Dot X)*X; 
		else if (DodgeMove == DODGE_Right)
			Velocity = -1.5*GroundSpeed*Y + (Velocity Dot X)*X; 

		Velocity.Z = 160;
		PlayOwnedSound(JumpSound, SLOT_Talk, 1.0, true, 800, 1.0 );
		PlayDodge(DodgeMove);
		DodgeDir = DODGE_Active;
		SetPhysics(PHYS_Falling);
	}
	
	function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)	
	{
		local vector OldAccel;
		
		OldAccel = Acceleration;
		Acceleration = NewAccel;
		bIsTurning = ( Abs(DeltaRot.Yaw/DeltaTime) > 5000 );
		if ( (DodgeMove == DODGE_Active) && (Physics == PHYS_Falling) )
			DodgeDir = DODGE_Active;	
		else if ( (DodgeMove != DODGE_None) && (DodgeMove < DODGE_Active) )
			Dodge(DodgeMove);

		if ( bPressedJump )
			DoJump();
		if ( (Physics == PHYS_Walking) && (GetAnimGroup(AnimSequence) != 'Dodge') )
		{
			if (!bIsCrouching)
			{
				if (bDuck != 0)
				{
					bIsCrouching = true;
					PlayDuck();
				}
			}
			else if (bDuck == 0)
			{
				OldAccel = vect(0,0,0);
				bIsCrouching = false;
				TweenToRunning(0.1);
			}

			if ( !bIsCrouching )
			{
				if ( (!bAnimTransition || (AnimFrame > 0)) && (GetAnimGroup(AnimSequence) != 'Landing') )
				{
					if ( Acceleration != vect(0,0,0) )
					{
						if ( (GetAnimGroup(AnimSequence) == 'Waiting') || (GetAnimGroup(AnimSequence) == 'Gesture') || (GetAnimGroup(AnimSequence) == 'TakeHit') )
						{
							bAnimTransition = true;
							TweenToRunning(0.1);
						}
					}
			 		else if ( (Velocity.X * Velocity.X + Velocity.Y * Velocity.Y < 1000) 
						&& (GetAnimGroup(AnimSequence) != 'Gesture') ) 
			 		{
			 			if ( GetAnimGroup(AnimSequence) == 'Waiting' )
			 			{
							if ( bIsTurning && (AnimFrame >= 0) ) 
							{
								bAnimTransition = true;
								PlayTurning();
							}
						}
			 			else if ( !bIsTurning ) 
						{
							bAnimTransition = true;
							TweenToWaiting(0.2);
						}
					}
				}
			}
			else
			{
				if ( (OldAccel == vect(0,0,0)) && (Acceleration != vect(0,0,0)) )
					PlayCrawling();
			 	else if ( !bIsTurning && (Acceleration == vect(0,0,0)) && (AnimFrame > 0.1) )
					PlayDuck();
			}
		}
	}
			
	event PlayerTick( float DeltaTime )
	{
		if ( bUpdatePosition )
			ClientUpdatePosition();

		PlayerMove(DeltaTime);
	}

	function PlayerMove( float DeltaTime )
	{
		local vector X,Y,Z, NewAccel;
		local EDodgeDir OldDodge;
		local eDodgeDir DodgeMove;
		local rotator OldRotation;
		local float Speed2D;
		local bool	bSaveJump;
		local name AnimGroupName;

		GetAxes(Rotation,X,Y,Z);

		aForward *= 0.4;
		aStrafe  *= 0.4;
		aLookup  *= 0.24;
		aTurn    *= 0.24;

		// Update acceleration.
		NewAccel = aForward*X + aStrafe*Y; 
		NewAccel.Z = 0;
		// Check for Dodge move
		if ( DodgeDir == DODGE_Active )
			DodgeMove = DODGE_Active;
		else
			DodgeMove = DODGE_None;
		if (DodgeClickTime > 0.0)
		{
			if ( DodgeDir < DODGE_Active )
			{
				OldDodge = DodgeDir;
				DodgeDir = DODGE_None;
				if (bEdgeForward && bWasForward)
					DodgeDir = DODGE_Forward;
				if (bEdgeBack && bWasBack)
					DodgeDir = DODGE_Back;
				if (bEdgeLeft && bWasLeft)
					DodgeDir = DODGE_Left;
				if (bEdgeRight && bWasRight)
					DodgeDir = DODGE_Right;
				if ( DodgeDir == DODGE_None)
					DodgeDir = OldDodge;
				else if ( DodgeDir != OldDodge )
					DodgeClickTimer = DodgeClickTime + 0.5 * DeltaTime;
				else 
					DodgeMove = DodgeDir;
			}
	
			if (DodgeDir == DODGE_Done)
			{
				DodgeClickTimer -= DeltaTime;
				if (DodgeClickTimer < -0.35) 
				{
					DodgeDir = DODGE_None;
					DodgeClickTimer = DodgeClickTime;
				}
			}		
			else if ((DodgeDir != DODGE_None) && (DodgeDir != DODGE_Active))
			{
				DodgeClickTimer -= DeltaTime;			
				if (DodgeClickTimer < 0)
				{
					DodgeDir = DODGE_None;
					DodgeClickTimer = DodgeClickTime;
				}
			}
		}
		
		AnimGroupName = GetAnimGroup(AnimSequence);		
		if ( (Physics == PHYS_Walking) && (AnimGroupName != 'Dodge') )
		{
			//if walking, look up/down stairs - unless player is rotating view
			if ( !bKeyboardLook && (bLook == 0) )
			{
				if ( bLookUpStairs )
					ViewRotation.Pitch = FindStairRotation(deltaTime);
				else if ( bCenterView )
				{
					ViewRotation.Pitch = ViewRotation.Pitch & 65535;
					if (ViewRotation.Pitch > 32768)
						ViewRotation.Pitch -= 65536;
					ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
					if ( Abs(ViewRotation.Pitch) < 1000 )
						ViewRotation.Pitch = 0;	
				}
			}

			Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
			//add bobbing when walking
			if ( !bShowMenu )
				CheckBob(DeltaTime, Speed2D, Y);
		}	
		else if ( !bShowMenu )
		{ 
			BobTime = 0;
			WalkBob = WalkBob * (1 - FMin(1, 8 * deltatime));
		}

		// Update rotation.
		OldRotation = Rotation;
		UpdateRotation(DeltaTime, 1);

		if ( bPressedJump && (AnimGroupName == 'Dodge') )
		{
			bSaveJump = true;
			bPressedJump = false;
		}
		else
			bSaveJump = false;

		if ( Role < ROLE_Authority ) // then save this move and replicate it
			ReplicateMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
		else
			ProcessMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
		bPressedJump = bSaveJump;
	}

	function BeginState()
	{
		if ( Mesh == None )
			SetMesh();
		WalkBob = vect(0,0,0);
		DodgeDir = DODGE_None;
		bIsCrouching = false;
		bIsTurning = false;
		bPressedJump = false;
		if (Physics != PHYS_Falling) SetPhysics(PHYS_Walking);
		if ( !IsAnimating() )
			PlayWaiting();
		[COLOR=red]if(bAntiBunnyHopping==false)
		{
			bCanJump=false;
			Enable('Timer');
			SetTimer(NoJumpingTime,false);
		}	[/COLOR]
	}
	
	function EndState()
	{
		WalkBob = vect(0,0,0);
		bIsCrouching = false;
	}
}


defaultproperties
{
	[COLOR=red]NoJumpingTime=2[/COLOR]
	JumpZ=200
     FaceSkin=3
     FixedSkin=2
     TeamSkin2=1
     DefaultSkinName="SoldierSkins.blkt"
     DefaultPackage="SoldierSkins."
     LandGrunt=Sound'Botpack.MaleSounds.(All).land10'
     CarcassType=Class'Botpack.TMale2Carcass'
     SelectionMesh="Botpack.SelectionMale2"
     SpecialMesh="Botpack.TrophyMale2"
     MenuName="Nisse"
     VoiceType="BotPack.VoiceMaleTwo"
     Mesh=LodMesh'Botpack.Soldier'
}
 

Mychaeel

New Member
Sorry, I didn't work my way through all that code. Here's my suggestion, and it works:
Code:
class NoBunny extends TMale1;


function DoJump(optional float F) {

  if (bCanJump)
    Super.DoJump(F);
}


state PlayerWalking {

  function Landed(vector HitNormal) {
  
    bCanJump = false;
    SetTimer(1.0, false);
  
    Super.Landed(HitNormal);
  }
  
  
  event Timer() {
    
    bCanJump = true;
  }
}
Simply setting bCanJump to false doesn't have any influence on a player's capability to jump; that's why I overwrote the DoJump function. The rest is just as suggested above (without copying the entire Landed function from the superclass).
 

ZitherMan

New Member
Oct 11, 2001
24
0
0
oh heck, why didnt i see that?
thank you for pointing out the super function possibilities.

Thank you very very much.
And thanks to every one who helped me.