Fun With Beams!
This video shows the Ship Creature’s charge up affect as it prepares to blast the ground to create new structures or deal with unauthorized base visitors!
In this video I am using several kinds of beams in several different ways!
The first part of this video demos how the flying creatures now maintain a certain height above the terrain, calculated while taking their rather unusual shape into account This height can be controlled by Designers in my BP Defaults for the creature.
**Beam Types**
1. straight beam, with source in local space, target in world space. Target is set in C++ to match position of the unit.
2. arced beam, with a tangent that is getting set in code, source in local, target in world/absolute space
3. straight beam with a source point in world space that is set in code, and a target that is in world space, also set in c++.
4. Electrical beam whose noise factor is a particle parameter that I set in code to match the duration of the effect as chosen by Designers via BP defaults.
Notice how the electrical beam starts scattered and becomes focused over the duration of the effect, again all controlled in C++.
The Hardest Part
The hardest part of what you see in the video was making the tangents for the arced beams stay consistent no matter which way the ship is looking in order to point directly at its target!
I had to use an odd hybrid of world and local space to accomplish this
Here’s what the code ended up looking like!
//World Space Location of Target
NewBeamLoc = FMath::VInterpTo(
NewBeamLoc,
(VISVALID(Tracking_Actor)) ? Tracking_Actor->GetActorLocation() : Tracking_Location,
GDELTATIME,
12
);
//Half way between Eye of Creature and Target Location
const FVector MidPoint = (NewBeamLoc + GetEyeLocation())/2;
int32 Index = 0;
for(UParticleSystemComponent* Comp : BeamArcs)
{
if(VISVALID(Comp))
{
//TEMP SHOULD REALLY BE HGIHER UP
Comp->SetVectorParameter(FName("Target"),MidPoint);
//Set the particle tangent position!
if(ArcTangents.IsValidIndex(Index))
{
//Local Space settings set by Designers in Editor
// as this controls the overall appearance of the arc.
// not modified during runtime.
FVector BPTangent = ArcTangents[Index];
//World Dir
FVector DirToTarget = (NewBeamLoc - GetEyeLocation()).SafeNormal();
//World Right Vector
FRotator WorldRight = FRotator(0,DirToTarget.Rotation().Yaw,0);
WorldRight.Yaw += 90;
//Oddly enough, Tangent has to start at 0! Strange but true!
// (would have thought it would be be the beam anchor location)
FVector Tangent = ZEROVECTOR;
//Forward
Tangent = DirToTarget * BPTangent.X;
//Right
Tangent = WorldRight.Vector() * BPTangent.Y;
//Up
Tangent.Z = BPTangent.Z;
//Tangent Beam Particle Parameter
Comp->SetVectorParameter("Arc",Tangent);
}
Index++;
}
}
Things to Note In My Code
1. The Designers can control the actual arcs of the beams in local space using a dynamic array of Vectors that I exposed to BP Defaults for the creature.
2. I am having to obtain the world direction and the world right direction between the eye of the Creature its current target, and then convert the local space coordinates set in BP into world positions. These world positions are the locations for the beam tangents that I set via beam particle parameter in Cascade.
3. **The end result is that the beam arcs stay consistent no matter how the creature rotates,** but, the beams are still tracking a world space location and the arched beams end at the midpoint betwen ship and its world space target!
Enjoy the Video!
♥
Rama