Original Unreal Character

WeatherStateTransitionGIF

Project Overview

I’ve designed and created a character for a game that explores themes surrounding mental health struggles. While I don’t have a formal Game Design Document (GDD) yet, I have notes and ideas to help establish the game’s direction and eventually develop them into one. The game’s general premise revolves around descending into a pit that symbolizes a downward spiral.

However, I’ve put this off because I feel I need more experience to be able to execute my vision for it. Additionally, modeling, rigging, and animating 3D characters requires a significant time investment.

While the project is still in its early stages, I’ve begun exploring character design and overall direction. Here’s a look at what I’ve developed so far.

Character Design & Animation Process

So far, I’ve created one character model for the player. Since I’m more comfortable with pixel art than other forms of digital art, I started by designing the character in Aseprite, using visual references to help establish the character’s overall look and direction as an explorer in a fantasy world. I then used this design as a starting point for creating the 3D model.

I used Blender to model, rig, and animate the character in a low-poly style. For most animations, I used retargeted Mixamo animations as a starting point, then modified them to better suit the character and the movement I’m looking for. I also animate certain actions, such as the attacks, by hand.

Additionally, I use physics assets to control the character’s tail and waist apron, allowing them to respond dynamically instead of trying to create realistic motion by hand.

The animations are still in a very early stage. I’m using most of them as placeholders to have the visuals while I implement movement mechanics and interactions. I’m also considering adjustments to the character’s model based on issues I’ve encountered with the clothing physics, as well as some design changes. For example, the waist apron doesn’t always interact well with certain animations, particularly sliding along the ground. I’m exploring whether I can modify the character’s design as an alternative to having to design my animations around the physics assets.

CharacterScreenShot

Player character model

This is what my animation graph state machine currently looks like:

  • Hang: the player can grab onto ledges and then jump up or slide down walls.
  • Wall Slide: when the player is hanging onto a ledge they can slide down the wall and kick off of it.
  • Pivot: when the player inputs the opposite direction while walking they slide to a stop. I’m planning on the player being able to input an additional action during this period, like you can in the game Pseudoregalia.

AnimationGraph

The video shows the player attacking, sliding, grabbing onto ledges, jumping up, and sliding down walls while kicking off of them. I've also enabled several debug visualizations to show the collision checks used by these different movement actions.
Character Clone

Currently in my game the player has a clone mechanic, with the idea being that you can utilize your clone to aid you in different actions. Right now the player can use the clone to boost them up when on the ground or in the air. I plan on adding additional ways the clone can combo with the player’s actions, such as when they attack.

The video shows the clone first being used to boost up off of the ground, then shows how the player can use the their past actions to get a boost up to a higher platform.

The clone works like this:

As the player moves they store data to be able to replicate the move, similar to how the save data for networking works.

USTRUCT(BlueprintType)
struct FPlayerRecordedFrame
{
	GENERATED_BODY()

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	float speed;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FVector Location;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FRotator Rotation;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FVector Velocity;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	// Montage info
	ERecordedMontage MontageID = ERecordedMontage::None;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	float MontagePosition = 0.f;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FName CurrentMontageSection = NAME_None;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	bool bIsFalling = false;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	bool bIsHanging = false;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	bool bIsPivoting = false;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	bool bIsWallSlide = false;
};

It’s not necessary to record every frame, so we record the player’s state at regular intervals instead.

For example, we could record a snapshot every 0.02 seconds (50 times per second) rather than recording every game frame. This will often reduce the amount of data we store, which is important because we’re maintaining a list of past frames to pass to our clone so it can recreate the player’s movements and animations. The longer the recording duration and the more frequently we record, the more snapshots we need to store.

I also have the option for the clone to continue to follow the player’s actions after catching up with the history, which you can see and the end of the following code. I think this helps to make the clone more useful.

void AZippyCharacter::Tick(float DeltaTime)
{
	// Super is a special Unreal-provided alias for the parent class of your current class
	// this is like call base.Tick() in C#
	Super::Tick(DeltaTime);

	// So, the following code is for recording our clone. For our clone, we record
	// on an interval so that we are not constantly recording. We not need a super high
	// level or precision.
	TimeSinceLastRecord += DeltaTime;

	if (TimeSinceLastRecord >= RecordInterval)
	{
		TimeSinceLastRecord -= RecordInterval;

		// This is how we built the current frame data for recording.
		FPlayerRecordedFrame Frame;

		// We can get the location, rotation, and velocity directly from ACharacter
		Frame.Location = GetActorLocation();
		Frame.Rotation = GetActorRotation();
		Frame.Velocity = GetVelocity();
		
		// But then we also need to store the player's animation data for whether the clone
		// should be sliding/jumping/attacking.
		if (UAnimInstance* AnimInst = GetMesh()->GetAnimInstance())
		{
			// the players animation blueprint. We copy and store all of the variables that we need
			// for determining the animation state.
			if (UMyPlayerAnimInstance* PlayerAnimBP = Cast<UMyPlayerAnimInstance>(AnimInst))
			{
				Frame.bIsFalling   = PlayerAnimBP->bIsFalling;
				Frame.bIsHanging   = PlayerAnimBP->bIsHanging;
				Frame.bIsPivoting  = PlayerAnimBP->bIsPivoting;
				Frame.bIsWallSlide = PlayerAnimBP->bIsWallSlide;
				Frame.speed        = PlayerAnimBP->speed;
			}
			
			// we use a montage for the attack animation and sliding, so we also want 
			// to store which section of the montage we are playing. We need montage Id
			// because our montage mapping contains multiple montages.
			// Using a montage like this also allows for swapping out the attack animation
			// if i wanted to use something different for the clone, which I've considered.
			if (UAnimMontage* Montage = AnimInst->GetCurrentActiveMontage())
			{
				Frame.MontageID            = MontageMapping ? MontageMapping->GetEnumForMontage(Montage) : ERecordedMontage::None;
				Frame.CurrentMontageSection = AnimInst->Montage_GetCurrentSection(Montage);
				Frame.MontagePosition       = AnimInst->Montage_GetPosition(Montage);
			}
		}

		// Always record history
		PastFrames.Add(Frame);
		

		// Make it so that we only keep RecordDuration of the history.
		int32 MaxFrames = FMath::CeilToInt(RecordDuration / RecordInterval);
		if (PastFrames.Num() > MaxFrames)
		{
			PastFrames.RemoveAt(0);
		}
		

		// When our clone is active, we want to keep recording and pushing our frames into
		//  it for a little extra duration so that it keeps following us instead of strictly
		// stopping at where we first pressed the button. So, while we haven't reached that extra 
		// duration, keep pushing our frames into it.
		if (bCloneRecordingActive && ActiveClone)
		{
			ActiveClone->AppendFrame(Frame);

			CloneRecordingTimer += RecordInterval;
			if (CloneRecordingTimer >= CloneExtraRecordDuration)
			{
				bCloneRecordingActive = false;
				ActiveClone = nullptr;
			}
		}
	}
}

Then when we spawn the clone, we pass the past frame list to the clone and maintain a reference to it in this player.

void AZippyCharacter::SpawnClone()
{
	// If we don't have the clone actor or we don't have any past frames,
	// don't spawn the clone.
	if (!PlayerShadowCloneClass || PastFrames.Num() == 0) 
		return;

	// Start recording window
	bCloneRecordingActive = true;
	CloneRecordingTimer = 0.f;

	FVector SpawnLocation = PastFrames[0].Location;
	FRotator SpawnRotation = PastFrames[0].Rotation;

	// spawn the clone actor at the starting location and rotation
	ActiveClone = GetWorld()->SpawnActor<APlayerShadowClone>(PlayerShadowCloneClass, 
                                                             SpawnLocation,
                                                             SpawnRotation);

	// If we successfully created the Clone, then initialize it.	
	if (ActiveClone)
	{
		ActiveClone->InitOwner(this);
		ActiveClone->SetOwner(this);   // built-in UE owner
		ActiveClone->InitReplay(PastFrames);
	}
}
Custom Character Physics

I use a custom PhysicsRotation function for my character’s dash/slide. The idea with this movement mechanic is that we restrict the player’s rotation at the start of the slide and allow for more rotation influence at the end of the slide using a curve. We also only want input within a certain threshold to influence the rotation, as I want to avoid the behavior of the player turning quickly when the input vector is in the opposite direction of the forward vector. To do this, I calculate the angle between the vectors using the arc cosine of the dot product 2 , since we normalize the input vectors, and then compare it to a threshold.

\[a\cdot b = \|\mathbf{a}\||\mathbf{b}||\\cos \left(\theta \right)\] \[\cos \left(\theta \right) = \left( \frac{a\cdot b}{\|\mathbf{a}\||\mathbf{b}\|}\right)\] \[\theta = \arcsin\left( \frac{a\cdot b}{\|\mathbf{a}\||\mathbf{b}\|}\right)\]

PlayerSlideGIF

The player's forward vector is the green arrow. The input direction while sliding is the red arrow with the blue head. Notice that the player turns more at the end of the slide.
void UZippyCharacterMovementComponent::DashPhysicsRotation(float DeltaTime)
{
	if (!CharacterOwner) return;

	FVector WorldInput = GetLastInputVector();
	WorldInput.Z = 0.f;

	if (!WorldInput.IsNearlyZero())
	{
		// Get the players forward vector on the xy plane
		FVector PlayerForward = CharacterOwner->GetActorForwardVector();
		PlayerForward.Z = 0.f;
		PlayerForward.Normalize();

		FVector DesiredDir = WorldInput.GetSafeNormal();

		// the idea is that we use the dot product, which is how aligned the two input vectors are
		// and we only rotate the player if the dot product is greater than some threshold
		// meaning we want the vector to be aligned.
		double dot = FVector::DotProduct(PlayerForward, DesiredDir);

		// the dot can be represented by the formula a*b = |a||b|cos(theta). We can rearange the
		// formula to put cos(theta) on one side and then solve for theta by taking the arc cosine
		// to get the angle between the two vectors.
		float Angle = FMath::RadiansToDegrees(acosf(dot));

		// Grab desired yaw directly from world input.
		// Yaw is the angle around the up axis, which just ends up being like
		// the rotation around x y plane with our input being on that plane.
		float DesiredYaw = WorldInput.Rotation().Yaw;

		// We use a cuve to represent how much control the player has over their rotation
		// over the slide/dash time, with the idea being that we restrict motion at the start,
		// and allow for more near the end.
		float NormalizedTime = DashElapsed / DashDuration;
		float DashRotationRate = BaseDashRotationRate;
		if (DashTurnCurve)
		{
			DashRotationRate *= DashTurnCurve->GetFloatValue(NormalizedTime);
		}

		// we only want to rotate the player if their input is somewhat aligned with
		// their forward vector.
		if (Angle < DashAngleThreshold) 
		{
			// define a new rotation that rotates the player around the up axis
			FRotator DesiredRot(0.f, DesiredYaw, 0.f);
			
			// current actor rotation
			FRotator CurrentRot = CharacterOwner->GetActorRotation();
			
			// lerp between the current actor rotation and our new desired rotation and assign it.
			FRotator NewRotation = FMath::RInterpConstantTo(CurrentRot, DesiredRot, DeltaTime, DashRotationRate);
			CharacterOwner->SetActorRotation(NewRotation);
		}
	}
}

The physics function itself controls the player’s horizontal velocity using a curve and then checks and handles collisions.

void UZippyCharacterMovementComponent::PhysDash(float DeltaTime, int32 Iterations)
{
	if (DeltaTime < MIN_TICK_TIME)
		return;

	DashElapsed += DeltaTime;

	// End dash if time is up
	if (DashElapsed >= DashDuration)
	{
		EndDash();
		return;
	}

	// Use a curve for the slide / dash speed
	float NormalizedTime = DashElapsed / DashDuration;
	float Speed = StartSlideSpeed;
	if (DashSpeedCurve)
	{
		float CurveScale = DashSpeedCurve->GetFloatValue(NormalizedTime);
		Speed *= CurveScale; 
	}

	// Always dash along forward vector
	FVector Forward = CharacterOwner->GetActorForwardVector();
	Forward.Z = 0.f; 
	Forward.Normalize();

	// we keep the players current vertical velocity component and just control the horizontal plane
	FVector DashVel = Forward * Speed;
	Velocity.X = DashVel.X;
	Velocity.Y = DashVel.Y;

	// check for collisions with the next move. collision-aware movement
	FVector Delta = Velocity * DeltaTime;
	FHitResult Hit;
	SafeMoveUpdatedComponent(Delta, UpdatedComponent->GetComponentQuat(), true, Hit);

	// handle impact if it happens
	if (Hit.IsValidBlockingHit())
	{
		HandleImpact(Hit, DeltaTime, Delta);
		SlideAlongSurface(Delta, 1.f - Hit.Time, Hit.Normal, Hit, true);
	}

	// Floor check to hug ground
	FFindFloorResult FloorResult;
	FindFloor(UpdatedComponent->GetComponentLocation(), FloorResult, false);


	// If no floor, switch to falling
	if(!FloorResult.IsWalkableFloor())
	{
		EndDash();
		return;
	}
	
	// Snap down if very close to the ground (like walking does)
	const float FloorDist = FloorResult.FloorDist;
	
	// floor distance is a great enough distance to consider it significant
	bool significant = FloorDist > KINDA_SMALL_NUMBER;

	// we use a floor snap threshold just as a safety measure to prevent large snaps if the floor results
	// says the floor is far away
	if (significant && FloorDist < FloorDistSnapThreshold)
	{
		FVector NewLoc = UpdatedComponent->GetComponentLocation();
		NewLoc.Z -= FloorDist; 
		UpdatedComponent->SetWorldLocation(NewLoc, false, nullptr, ETeleportType::TeleportPhysics);
	}

	CurrentFloor = FloorResult;
}
Ledge Detection

In my game, ledge grabbing is part of the player’s core movement mechanics. While falling, the player can grab onto surfaces that I’ve marked as climbable. From this state, they can jump up or drop off the ledge. If there’s a wall beneath them, they can also slide down it.

The mechanic works through the following steps:

  1. Check the player’s movement state. Check whether the player’s vertical velocity is below zero and whether they’re airborne. This ensures that ledge detection only occurs while the player is falling.

  2. Check for a suitable surface. Perform two sphere casts. The bottom sphere must overlap a climbable surface, while the top sphere must remain unobstructed to ensure there’s enough open space above the ledge.

  3. Calculate the ledge’s position and normal. Cast a grid of rays to calculate an average surface normal and position. Using multiple rays provides a better representation of the surface than relying on a single hit. However, there’s a balance between accuracy and performance, since each additional raycast adds to the cost of the detection. Since the primary use of ledge grabbing in my game is navigating cliffsides and other environment, I plan on using relatively low-poly geometry. As a result, I don’t need a particularly dense grid to get an accurate enough representation. In my implementation, I use nine raycasts.

  4. Enter the ledge-hold state. Switch to a custom ledge-hold state in my character movement component. The player is then snapped into position using the calculated average normal and position, with an additional offset to align them with the ledge. Their velocity is also set to zero.

PlayerGrabGIF

The red raycast grid are the rays used to average the surface position and normal. The two spheres represent the top and bottom sphere casts. When the bottom cast hits a climable surface and the top raycast doesn't hit anything, the player snaps onto the wall.
LINKS
  1. In-Depth Character Movement Component Guide by Delgoodie
  2. Angle From Dot Product