write me third person unreal engine 5.4 blueprint for character that can attach to a wall and go forward or go backward (like wall running but with more control)
and explain it detail by detail exactly how should i implement this only using blueprint nodes
Assistant
User
how do i do this using splines
Assistant
User
explain the 5th step trace better
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! Below is a detailed guide for implementing a wall-attaching character with forward and backward movement control in Unreal Engine 5.4 using Blueprints. This guide assumes a basic understanding of Unreal Engine Blueprints.
Step-by-Step Implementation:
1. Character Setup:
Create a New Character:
Open Unreal Engine 5.4.
Create a new Third-Person project.
In the Content Browser, right-click and create a new Blueprint Class. Select Character as the parent class, and name it something like WallRunCharacter.
2. Add Components:
Add Collision Component:
Open the WallRunCharacter Blueprint.
Add a Capsule Component for collision detection, if not already present.
Add Camera and Spring Arm:
Add a Spring Arm Component and then a Camera Component to the Spring Arm to enable camera control.
3. Define Inputs:
Setup Input Mappings:
Go to Project Settings and navigate to Input.
Add Action Mappings for AttachToWall, MoveForward, and MoveBackward.
Add Axis Mappings for movement if they are not already present (usually MoveForward and MoveRight).
4. Implementing Blueprint Logic:
Variables and States:
Create the following Boolean variables:
bIsWallRunning to check if the character is wall running.
bCanAttachToWall to control if the character can attach to the wall.
Trace for Wall:
In the Event Graph, use a Line Trace by Channel node to detect walls.
Add logic to check for a wall in Tick (but optimize it later).
On hit, set the bCanAttachToWall variable.
5. Wall Attach Logic:
Attach Procedure:
On AttachToWall input action, check if bCanAttachToWall is true.
Use Set Actor Location and Set Actor Rotation nodes to snap the character to the wall. Adjust the rotation to align with the wall’s surface normal.
Set bIsWallRunning to true.
Detach Procedure:
On release of AttachToWall input, set bIsWallRunning to false.
Re-enable normal gravity if disabled.
6. Movement Control:
Moving Forward and Backward:
Add Input actions for MoveForward and MoveBackward.
In the Event Graph, move the character along the wall using translation in the character’s local space.
Ensure movement only occurs if bIsWallRunning is true.
7. Blueprint Nodes Implementation:
Here's a bit more detail on the necessary blueprint nodes and their connections:
Line Trace for Wall:
Event Tick → Line Trace by Channel
Start: Get Actor Location
End: Get Actor Location + (Forward Vector * Desired Distance)
SetActorLocation and SetActorRotation to the hit location and surface normal
Set bIsWallRunning to true
Move Forward and Backward:
Add Input Axis for MoveForward and MoveBackward.
InputAxis MoveForward:
Branch (Check bIsWallRunning)
True: Add Movement Input (using right vector)
InputAxis MoveBackward:
Branch (Check bIsWallRunning)
True: Add Movement Input (using -right vector)
8. Testing and Polishing:
Enable/Disable Gravity:
Consider toggling gravity using Character Movement Component based on the wall running state.
Visual Feedback:
Optionally, add visual feedback or animations when attaching/detaching from the wall.
Optimization:
Optimize wall detection logic to avoid constant traces in Tick. Consider enabling traces only during certain states (e.g., while in the air near a wall).
This should give you a solid blueprint-based character that can attach to walls and move forward or backward along the wall. Each step has key nodes and logic interactions detailed for you to follow along in Unreal Engine 5.4.
Using splines for creating a controlled wall-running system in Unreal Engine 5.4 provides a more flexible and visually driven approach. Here's how you can leverage splines to set up a character that can attach to a wall and move forward or backward.
Step-by-Step Implementation Using Splines:
1. Character Setup:
Create a New Character:
Open Unreal Engine 5.4.
Create a new Third-Person project.
In the Content Browser, right-click and create a new Blueprint Class. Select Character as the parent class, and name it something like WallRunCharacter.
2. Add Spline Component:
Create a Wall Spline:
Right-click in the content browser, create a new Blueprint Class, and select Actor.
Name this Blueprint something like WallSplineActor.
Open WallSplineActor, add a Spline Component to it.
3. Define Inputs:
Setup Input Mappings:
Go to Project Settings and navigate to Input.
Add Action Mappings for AttachToWall, MoveForward, and MoveBackward.
Add Axis Mappings for movement if they are not already present (usually MoveForward and MoveRight).
4. Setting Up the Spline Actor:
Place Spline in Level:
Drag and drop WallSplineActor into your level.
Adjust its spline points to create the path along the wall which the character will traverse.
5. Implementing Character Blueprint:
Variables and States:
Create the following variables:
bIsWallRunning (Boolean) - to check if the character is wall running.
CurrentSpline (Spline Reference) - reference to the spline actor.
CurrentSplineDistance (Float) - to track the character's position along the spline.
Trace for Wall and Detect Spline:
In the Event Graph of WallRunCharacter, use a Line Trace by Channel node to detect walls and check for interaction with spline actors.
On hit, use Cast to WallSplineActor to confirm spline hit and set CurrentSpline.
6. Attach to Spline:
Attach Procedure:
On the AttachToWall input action:
Check if CurrentSpline is valid.
Use Find Location Closest to World Location on the CurrentSpline to snap the character to the nearest spline point.
Set bIsWallRunning to true.
Detach Procedure:
On release of the AttachToWall input, set bIsWallRunning to false.
7. Movement Along Spline:
Slider Movement Logic:
Add input actions for MoveForward and MoveBackward.
In the Event Graph, add logic to adjust CurrentSplineDistance based on input:
plaintext
InputAxis MoveForward:
Branch (Check bIsWallRunning)
True:
AddCurrentSplineDistance (+ DeltaTime * speed)
Set actor location to spline point at CurrentSplineDistance
InputAxis MoveBackward:
Branch (Check bIsWallRunning)
True:
SubtractCurrentSplineDistance (- DeltaTime * speed)
Set actor location to spline point at CurrentSplineDistance
Preventing Leaving the Spline's Bounds:
Clamp CurrentSplineDistance within the valid range (0 to Spline Length).
8. Blueprint Nodes Implementation:
Here's a corresponding blueprint node layout for some major steps:
Line Trace for Wall and Detect Spline:
Event Tick → Line Trace by Channel
Start: Get Actor Location
End: Get Actor Location + (Forward Vector * Desired Distance)
On Hit: Cast to WallSplineActor
If cast is successful, set CurrentSpline
Attach to Wall Spline:
InputAction AttachToWall (Pressed) → Branch (Check if CurrentSpline is valid)
True:
Find Location Closest to World Location (Current Spline)
Set Actor Location to that location
Set bIsWallRunning to true
Move Forward and Backward along Spline:
Move Forward:
InputAxis MoveForward
Branch (Check bIsWallRunning)
True: Add float to CurrentSplineDistance (Delta Time * Speed)
Get Spline Length → Clamp CurrentSplineDistance
Get Spline Point At Distance Along Spline (Using CurrentSpline and CurrentSplineDistance)
Set Actor Location to retrieved spline point location
Move Backward:
Similar to Move Forward, but subtract from CurrentSplineDistance.
9. Testing and Polishing:
Customizing Spline Path:
Adjust the spline points in WallSplineActor to refine the wall running path.
Visual Feedback and Animation:
Optional: Add visual effects or animations for smoother transitions when attaching or moving along the spline.
Optimization:
Optimize the line tracing in Tick by incorporating a trigger volume or another event-based approach to reduce constant checks.
By using splines, you gain precise control over the path the character will follow, provide a visual way to design those paths, and ensure consistent behavior along the walls. This method enhances flexibility and creates more intricate and controlled wall-running mechanics.
Sure! The tracing step is critical as it allows your character to detect walls and then determine if it's hitting a spline actor that defines the wall run path. Here's a deeper dive into the tracing logic and its implementation:
Step 5: Detailed Wall Trace and Spline Detection
Overview:
Using a line trace, we will detect walls and identify if the hit wall contains a spline component that the character can attach to for wall running. Once detected, the trace will return information about the spline, which will subsequently be used to align the character to the wall and initiate the wall running mechanics.
Detailed Implementation Steps:
1. Setup Trace Configuration:
Event Tick Usage:
In your WallRunCharacter Blueprint, you'll set up the tracing logic to run every frame or based on a more optimized event-driven approach.
2. Running the Line Trace:
Blueprint Nodes and Configuration:
Navigate to the Event Graph of your WallRunCharacter.
Utilize the Event Tick node cautiously as heavy logic inside it can impact performance. Alternatively, replace it with a more optimized approach like triggers or player movement events.
Detailed Node Sequence:
Event Graph Setup:
Drag off Event Tick and add a Sequence node to maintain clean execution flow.
For one pin of the Sequence, continue logic for the line trace.
Define Trace Start and End:
Start:
Use Get Actor Location to obtain the character's current location.
End:
Use Get Actor Forward Vector multiplied by a set distance (e.g., 200 units) to define how far the trace should go.
Combine Start location with End location using Vector + Vector node to get the trace's end point.
Line Trace Execution:
Use Line Trace by Channel node:
Connect Start and End outputs as described.
Set the Trace Channel (e.g., Visibility or a custom channel if necessary).
Line Trace Hit Result Processing:
Drag off Line Trace by Channel's Out Hit and break struct to access detailed hit information like Hit Actor and Hit Location.
3. Detecting and Validating Spline Actor:
Cast to WallSplineActor:
From the Hit Actor, drag out a wire and use Cast To WallSplineActor. This checks if the hit component is a WallSplineActor.
If the cast is successful (meaning the hit wall has a spline for wall running):
Set the CurrentSpline variable to the casted spline reference.
Optionally, store the Hit Location for positioning and alignment.
4. Storing Relevant Information:
Store Spline and Hit Information:
Set CurrentSpline reference to the hit spline actor.
Store Hit Location and Normal for future operations, like snapping and aligning the character to the wall.
Example Blueprint Node Setup:
Here's a precise blueprint setup for the trace logic:
Event Tick Setup:
Use Event Tick → Sequence
If using optimization, use a boolean check (e.g., bIsNearWall to avoid constant tracing).
Line Trace Configuration:
plaintext
- Get Actor Location → Start (Line Trace By Channel)
- Get Actor Forward Vector → Multiply by float (Distance, e.g., 200.0) → End (Vector + Vector)
- Line Trace By Channel (Visibility)
- Start: Actor Location
- End: Start + (Forward Vector * Distance)
Processing Hit Result:
plaintext
- Break Hit Result
- Hit Actor → Cast To WallSplineActor
- If Cast Succeeds:
- Set `CurrentSpline` to Cast Result
- (Optional) Set `CurrentSplineDistance` to 0 or value based on closest point logic
Validate and Save Spline Reference:
Use Branch (Boolean bIsWallRunning, controlled elsewhere to handle state checks).
plaintext
Event Tick
|
Sequence
|
Line Trace By Channel
|
Break Hit Result
|
Cast To WallSplineActor
|
Branch: Is Valid(CurrentSpline) --> True
| |
Set Spline Ref |
Set CurrentSplineDistance If valid |
Summary:
Line Trace Execution: Uses the character’s position and forward vector to detect walls ahead.
Hit Processing: Analyzes the hit result to determine if the hit object is a spline actor.
Spline Reference: On successful detection, the character saves the spline reference and prepares for wall attachment/run.
This setup will ensure that your character only initiates wall running when detecting a predefined spline actor, thereby allowing controlled wall running along the designed path.