Skip to content
Pablo Rodriguez

Weapon Interaction System

Create a flexible interaction system that handles weapon pickup, environmental interactions, and world navigation.

Set up interaction keybind:

  • Input Action: IA_Interact
  • Keybind: F key
  • Input Mapping: Add to IMC_Default context
  • Trigger: Started trigger for immediate response

Implement sphere trace for interaction detection:

// Player Interaction Trace
OnInteractPressed() {
start_location = GetActorLocation() + (ForwardVector * 100);
end_location = GetActorLocation() + (ForwardVector * 150);
SphereTraceByChannel(start_location, end_location, 80, 'Interact');
if (hit_result.IsValid()) {
hit_result.Actor.Interface_Interact(Self);
}
}

Create dedicated interaction collision channel:

  • Project Settings > Collision: Add new trace channel “Interact”
  • Default Response: Ignore
  • Interactable Objects: Set to Block on Interact channel

Create actors for weapon selection and pickup:

  • Arrow Component: Root for positioning control
  • Skeletal Mesh: Display weapon appearance
  • Box Collision: Interaction detection volume
  • Rotating Movement: Visual appeal
  • Animation Stance Enum Variable: Determines weapon type
  • Instance Editable: Allow level designers to set weapon type
  • Construction Script: Update skeletal mesh based on weapon type
// Weapon Type Selection
F_Set_Weapon_Type() {
switch(Weapon_Type) {
case Shield: SetSkeletalMesh(ShieldAsset); break;
case TwoHanded: SetSkeletalMesh(TwoHandedAsset); break;
case Rifle: SetSkeletalMesh(RifleAsset); break;
case Bow: SetSkeletalMesh(BowAsset); break;
case Stealth: SetSkeletalMesh(DaggerAsset); break;
case Unarmed: SetSkeletalMesh(BubbleWandAsset); break;
}
}

Create communication between weapon pickups and player:

  • Player Interface Function: Interface_Equip_Weapon
  • Weapon Type Parameter: Pass selected weapon type to player
  • Animation Stance Update: Change player’s current weapon stance

Create versatile teleporter for doors, ladders, and teleportation:

  • Arrow Component: Root component for positioning
  • Static Mesh: Visual representation (door, ladder, teleport pad)
  • Box Collision: Interaction detection
  • Sphere Components: Teleport destination markers (Sphere_A, Sphere_B)
// Smart Teleportation System
OnInteract(PlayerActor) {
player_location = PlayerActor.GetActorLocation();
distance_to_sphere_A = Distance(player_location, Sphere_A.Location);
distance_to_sphere_B = Distance(player_location, Sphere_B.Location);
if (distance_to_sphere_A > distance_to_sphere_B) {
PlayerActor.SetActorLocation(Sphere_A.Location);
} else {
PlayerActor.SetActorLocation(Sphere_B.Location);
}
}

Create child blueprints for specific use cases:

  • Static Mesh: Door asset
  • Sphere Placement: One on each side of door
  • Use Case: Room transitions, building entrances
  • Static Mesh: Ladder asset
  • Sphere Placement: Top and bottom of ladder
  • Use Case: Vertical level transitions
  • Static Mesh: Magical/technological pad
  • Sphere Placement: One nearby, one at distant location
  • Use Case: Long-distance transportation

Expand statistic changer into comprehensive trap system:

  • Effects Array: Support multiple simultaneous effects
  • Effect Types: Health damage, knockback, jump pad boost
  • Customizable Power: Adjustable knockback strength, damage amounts
// Knockback Trap Effect
OnTrapTrigger(PlayerActor) {
trap_location = GetActorLocation();
player_location = PlayerActor.GetActorLocation();
knockback_direction = FindLookAtRotation(trap_location, player_location);
launch_vector = knockback_direction.ForwardVector * knockback_power;
PlayerActor.Interface_Knockback(launch_vector, knockback_power);
}

Transform knockback traps into jump pads:

  • Custom Direction: Override automatic direction calculation
  • Launch Vector: Set specific X/Y/Z launch values
  • Use Cases: Vertical boost, directional launching, traversal assistance

Enhance interaction system with clear feedback:

  • Interaction Prompts: UI indicators when objects can be interacted with
  • Highlight Effects: Visual emphasis on interactable objects
  • Audio Feedback: Sound effects for successful interactions

Fine-tune interaction detection:

  • Sphere Radius: 80 units provides good interaction range without being overly generous
  • Forward Offset: Start trace ahead of player to prevent wall-clipping issues
  • Trace Length: 50-unit trace length for responsive but not excessive range

Organize interaction objects for level design efficiency:

  • Child Actor System: Create variations without code duplication
  • Instance Variables: Allow customization per-instance
  • Template System: Standardized interaction objects for consistent behavior

The weapon interaction system provides the foundation for player progression, world navigation, and environmental puzzle-solving while maintaining clean, reusable code architecture.