#Projectile Motion Effects

1 messages · Page 1 of 1 (latest)

sturdy forge
#

Hey guys! I wanted to share a custom projectile movement component I created to add motion effects to the projectiles. I needed to diversify the abilities, so using different motions was a good option for that.

→ AuraProjectileMovementComponent.h: https://pastebin.com/DDnZzMnq
→ AuraProjectileMovementComponent.cpp: https://pastebin.com/XWsME1Mg

In the AuraProjectile class, I just changed the projectile movement component to this new class.
→ .h file:

UPROPERTY(VisibleAnywhere)
TObjectPtr<UAuraProjectileMovementComponent> ProjectileMovement;

→ .cpp file:

ProjectileMovement = CreateDefaultSubobject<UAuraProjectileMovementComponent>("ProjectileMovement");
#

And here the enums:
→ ProjectileMotionType:

UENUM(BlueprintType)
enum class EProjectileMotionType : uint8
{
  Default   UMETA(DisplayName = "Default"),
  Helix     UMETA(DisplayName = "Helix"),
  Snake     UMETA(DisplayName = "Snake"),
  Noise     UMETA(DisplayName = "Noise"),
  Pulse     UMETA(DisplayName = "Pulse"),
  ZigZag    UMETA(DisplayName = "ZigZag"),
  YoYo      UMETA(DisplayName = "Yo-Yo"),
  Bezier    UMETA(DisplayName = "Bezier Curve"),

  MAX       UMETA(Hidden)
};

→ MotionShiftMode:

UENUM(BlueprintType)
enum class EMotionShiftMode : uint8
{
  // Shifts the initial direction of the movement (left, right, clockwise...)
  Direction         UMETA(DisplayName = "Direction"),
  // Shifts in which phase the motion starts
  Phase             UMETA(DisplayName = "Phase"),
  // Shifts the frequency, duration or velocity of the motion
  Speed             UMETA(DisplayName = "Speed"),
  // Shifts the amplitude over time
  Growth            UMETA(DisplayName = "Growth"),
  // Shifts the speed factor of yo-yo's return phase
  YoYoReturnSpeed   UMETA(DisplayName = "Yo-yo Return Speed"),
  // Bezier only: shifts the control points rotations
  ControlPoint      UMETA(DisplayName = "ControlPoint"),

  MAX               UMETA(Hidden)
};
#

→ Pulse (slowdown x speedup cycle)

#

→ Yo-yo (reverts direction after a while)

#

In the ProjectileAbility class I also added some new variables for some cases that I need ability data:
→ .h file:

// Whether the Directional Shift should alternate on consecutive projectiles
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category="Projectile|Motion")
bool bMotionDirectionAlternates = false;
// Whether the Bezier final point will be the same as the ability Target Location
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category="Projectile|Motion")
bool bUseTargetLocationAsBezierFinalLocation = false;
// Whether Yo-Yo motion will make the return towards the avatar actor
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category="Projectile|Motion")
bool bYoYoReturnToAvatar = false;

→ .cpp file, in SpawnProjectile function, before calling Projectile->FinishSpawning:

if (bMotionDirectionAlternates)
{
  Projectile->ProjectileMovement->bDefinedDirections = true;
  Projectile->ProjectileMovement->DirectionMultiplier = ProjectileDirectionShift;
  ProjectileDirectionShift *= -1.f;
}

if (bUseTargetLocationAsBezierFinalLocation)
{
  Projectile->ProjectileMovement->bBezierOverride = true;
  const FTransform& StartTransform = Projectile->ProjectileMovement->UpdatedComponent->GetComponentTransform();
  const FVector LocalOffset = StartTransform.InverseTransformPosition(ProjectileTargetLocation);
  Projectile->ProjectileMovement->BezierEndOverride = LocalOffset;
}

if (bYoYoReturnToAvatar)
{
  Projectile->ProjectileMovement->bYoYoReturnToAvatar = true;
  Projectile->ProjectileMovement->AvatarActor = AvatarActor;
}
#

This adds even more motion effects, like:
→ MotionDirectionAlternates with 2 projectiles spawned at once

#

And we can tweak all variables in this custom projectile movement component details panel, in each Projectile BP. Adding a Motion Shift will add even more variation, by setting some randomness or increasing the amplitude of the motion over time

mellow quartz
#

Download files are not allowed

sturdy forge
#

let me check how I can share it here without it being a file

mellow quartz
sturdy forge
mellow quartz