For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Emulating Quake's Bunny Hop Mechanics

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
Post Reply
User avatar
makemeunreal
OldUnreal Member
Posts: 550
Joined: Sat Mar 23, 2013 7:51 pm

Emulating Quake's Bunny Hop Mechanics

Post by makemeunreal »

Hi there!

Although I despise playing Quake games our clanmate introduced us to Defrag thingy that is basically a tore-down version of Quake 3 relying on it's Bunny Hopping feature thus creating a "racing game" out of Quake 3.

I started experimenting with an emulation of this feature; on my level of coding knowledge of course and failed miserably.
(In case you are interested in the coding behind Quake's Buny Hopping feature:
I made a prototype tho.

Custom GameType that kills Fall Damage:

Code: Select all

//=============================================================================
// MMUGottaGoFastz.
//=============================================================================
class MMUGottaGoFastz expands DeathMatchGame;

function float PlayerJumpZScaling()
{
	if ( bHardCoreMode )
		return 1.5;
	else
		return 1.5;
}

function int ReduceDamage(int Damage, name DamageType, pawn injured, pawn instigatedBy)
{
    // Ignore fall damage
    if (DamageType == 'Fell')
        return 0;

    // Check if the injured pawn is in a neutral zone, if so, return 0 damage
    if (injured.Region.Zone.bNeutralZone)
        return 0;

    // If the damage is caused by no one (e.g., environmental damage), return the original damage
    if (instigatedBy == None)
        return Damage;

    // If in hardcore mode, don't modify damage
    if (bHardCoreMode)
        return Damage;

    // Skill level modification
    if ((instigatedBy.Skill < 1.5) && instigatedBy.IsA('Bots') && injured.IsA('PlayerPawn'))
        Damage = Damage * (0.7 + 0.15 * instigatedBy.skill);

    // Apply damage scaling based on instigator
    return (Damage * instigatedBy.DamageScaling);
}

And a pickup that aims to modify some player movement related stuff:

Code: Select all

//=============================================================================
// MMUBunnyBoots.
//=============================================================================
class MMUBunnyBoots expands Pickup;

var Vector PreviousLocation; // Declare PreviousLocation at the class level
var Vector AcceleratedVelocity; // Store the accelerated velocity
var bool JustLanded; // Track whether the player has just landed from a jump

state Activated
{
    function endstate()
    {
        if (Owner != None)
        {
            Pawn(Owner).Airspeed = Pawn(Owner).Default.Airspeed;
            Pawn(Owner).Groundspeed = Pawn(Owner).Default.Groundspeed;
            Pawn(Owner).Acceleration = Pawn(Owner).Default.Acceleration;
            Pawn(Owner).AirControl = Pawn(Owner).Default.AirControl;
        }
        bActive = false;
    }

    function AccelerateInAir()
    {
        // Check if the player is in the air
        if (Pawn(Owner).Physics == PHYS_Falling)
        {
            // Accelerate the player
            AcceleratedVelocity = Pawn(Owner).Velocity + Pawn(Owner).Velocity * 0.00000001; // Increase velocity by 10% each tick
        }
    }

    function Tick(float DeltaTime)
    {
        Super.Tick(DeltaTime);

        // Check if the player is moving downhill or in the air
        if (Pawn(Owner).Location.Z < PreviousLocation.Z || Pawn(Owner).Physics == PHYS_Falling)
        {
            // Apply accelerated velocity
            if (AcceleratedVelocity != vect(0,0,0))
            {
                Pawn(Owner).Velocity = AcceleratedVelocity;
            }
            else
            {
                // Accelerate the player
                Pawn(Owner).Velocity += Pawn(Owner).Velocity * 0.001; // Increase velocity by 10% when moving downhill or in the air
            }
        }
        else if (Pawn(Owner).Location.Z > PreviousLocation.Z)
        {
            // Decrease velocity when moving uphill
            Pawn(Owner).Velocity *= 0.75; // Reduce velocity by half when moving uphill
        }

        // Check if the player has just landed from a jump
        if (Pawn(Owner).Physics == PHYS_Walking && PreviousLocation.Z > Pawn(Owner).Location.Z)
        {
            JustLanded = true; // Set the flag when the player transitions from falling to walking
        }

        // Apply bounce effect if the player has just landed from a jump
        if (JustLanded)
        {
            // Apply bounce effect
            Pawn(Owner).Velocity *= 1.25; // Increase velocity by 50% upon landing
            JustLanded = false; // Reset the flag
        }

        // Update previous location
        PreviousLocation = Pawn(Owner).Location;
    }

    Begin:
        Pawn(Owner).Airspeed = Pawn(Owner).Default.Airspeed * 2.0;
        Pawn(Owner).Groundspeed = Pawn(Owner).Default.Groundspeed * 2.0;
        Pawn(Owner).Acceleration = Pawn(Owner).Default.Acceleration * 18.0;
        Pawn(Owner).AirControl = Pawn(Owner).Default.AirControl * 16.0;
        PreviousLocation = Pawn(Owner).Location; // Initialize PreviousLocation
        JustLanded = false; // Initialize JustLanded flag
}

state DeActivated
{
    Begin:
}
It is miserable even for a rookie attempt to emulate the movement we see there.
I wonder if anyone has ever tried implementing this in Unreal.
Also, do you know any way for the pickup to make the player retain it's gained speed when hitting the ground?
I also wonder why the player won't keep on accelerating both in the air and on the ground. Something seems to be capping it's speed above the Pickup's GroundSpeed modification.

Any help is appreciated.

Video:
User avatar
Blu3Haz3
OldUnreal Member
Posts: 284
Joined: Fri Apr 30, 2010 10:05 pm

Re: Emulating Quake's Bunny Hop Mechanics

Post by Blu3Haz3 »

I made something like this but it was a really crappy version of it. So the main reason you would decelerate on the ground is because of friction... you would probably have to recode\overwrite the friction coding I imagine in order to help deal with deceleration. The main difference between quake and unreal's friction I think is the rate of which you decelerate, thus the acceleration has to be strong enough (by gaining lots of speed), and the friction deceleration rate must not be instantaneous. I wonder now if the Friction code is done in Native. One of the major reasons Quake even allows for strafe jumping is because you can 'queue' the jump key before you even land I think. So once in the air, you never really touch the ground long enough for it to decelerate you. If you could rewrite the jump code so it can be executed again prior to landing then you should be able to avoid a whole lot of the issues with friction. thumbsup

also, you will probably need to write a dot function so you can get the view rotation and measure the difference in where you turn between jumps (to add acceleration)... this is what I did. I basically would create a vector a (the x rotation of where the player rotation when jump is initialized), and find the difference in vector b (the x rotation of where of the player when landing). Then store this in memory so you can assess whether or not the difference in view rotation is shrinking or growing using a condition statement. The only issue is this is nothing like the frame dependent code of strafe jumping, if you want the real deal you would have to look for help on frame independence and strafe jumping, and what is stopping a person from just hitting the dpi button on their mouse and just doing a 720 turn to get full speed? Also, in Quake the maxspeed is uncapped even on the ground where friction exists because the bug doesn't just apply in the air. It would be really important to fully understand Quake's physics coding, and I doubt there are any videos that go much further into detail about it. I think in Quake, every frame is analyzed for player rotation, which allows for more processing over wishdir in realtime. In Quake 3 at least, when strafe jumping if you ever stop moving your mouse you don't gain any speed unless your wishdir is in the perfect spot to maintain acceleration, this also applies to circle jumping which requires more mouse movement due to the friction of the ground.
Post Reply

Return to “UScript Board”