I’m performing a series of calculations in Blueprint that enumerate some C++ code, but I’m having issues with it, and I suspect its because Blueprint does not allow you to get the current value of a variable, add to it then set it all in the same function, is that right?
AnswerBase post here: Is +=, -=, *=, /= etc. possible in Blueprints? - Blueprint - Epic Developer Community Forums
At the bottom is the code I have transferred, this function is called every frame, and makes multiple changes to different variables as it runs through the code. Accel being the major one. I have what I believe to be the right method in Blueprint if it’s possible, but it doesn’t seem like it is. Does this mean I have to create Old versions of every variables as variables themselves, everytime I want to make a change before using it? Kinda sucks
Blueprint Attempt - Notice That I’m ‘Getting Accel’, then subtracting from it and setting it again
http://i239.photobucket.com/albums/ff29/thejamsh/Test_zpsf7a177d1.jpg
C++ Equivalent - Probably Loads of Errors Here But You See What I’m Doing
void ASHoverTank::VehicleMove()
{
float ControlMag = FMath::Min(1.0f, Throttle ^ 2, Strafe ^ 2);
float SpeedFront = Dot(Veloc, Front);
float SpeedRight = Dot(Veloc, Right);
float SpeedRatio;
FVector velocDiff;
FVector accelRequired;
float accelMag;
float accelDrag;
float accelLim;
float lenSqr;
float lenDot;
/* Apply Levelling */
/* Pitch and Roll Damping */
Alpha.Y = -alphaDamp * Omega.Y;
Alpha.X = -alphaDamp * Omega.X;
/* Terrain Normal Tracking */
TrackNormal = Normalize((normal.x, normal.y, normal.z + 2));
ScaledTrack = AlphaTrack * ThrustRatio;
Alpha.Y -= ScaledTrack * Dot(TrackNormal, Front);
Alpha.X += ScaledTrack * Dot(TrackNormal, Right);
/* Use Strafe To reduce skidding during turns (Might not be crucial) */
if (AccelThrust > 0)
{
float forceCentrip = -SpeedFront * Omega.z * ControlMag;
float antiSkid = FMath::Clamp(forceCentrip / AccelThrust, -1, 1);
Strafe += antiSkid - antiSkid * FMath::Abs(Strafe);
}
/* Apply Throttle and Strafe, Maximum Speed In The Forward Direction */
if (Throttle > 0)
{
VelocFront = VelocForward;
}
else
{
velocFront = -velocReverse;
}
/* Difference Between Current And Desired Velocity */
velocDiff = (Throttle * VelocFront - SpeedFront) * Front + (Strafe * VelocRight - SpeedRight) * Right;
/* Thrust Acceleration required to eliminate the difference */
FVector accelRequired = velocDiff / DeltaSeconds;
FVector accelRequired -= Dot(accelRequired, normal) * normal;
float accelMag = Dot(accelRequired, accelRequired);
/* Ratio between current and maximum speed */
if (VelocForward > 0)
{
SpeedRatio = FMath::Clamp(Speed / VelocForward, 0, 1);
}
else
{
SpeedRatio = 0.0f;
}
/* Maximum drag Acceleration */
accelDrag = SpeedRatio * (accelDragFull - accelDragStop) + accelDragStop;
/* Acceleration Limit Based On Controls */
accelLim = ThrustRatio * (ControlMag * (normal.z * accelThrust - accelDrag) + accelDrag);
/* If required acceleration is higher than the limit */
if (accelMag > accelLim * accelLim)
{
Accel += accelLim / FMath::Sqrt(accelMag) * accelRequired
}
/* Apply braking force if it will help */
if (ControlMag > 0.01)
{
lenSqr = Speed * Speed * Dot(VelocDiff, VelocDiff);
if (lenSqr > 1)
{
lenDot = Dot(Veloc, VelocDiff);
if (lenDot < 0)
{
Brake = FMath::Max(Brake, -ControlMag * lenDot / FMath::Sqrt(lenSqr))
}
else
{
Accel += accelRequired;
}
}
}
/* Apply Brakes */
V = Veloc + DeltaSeconds * Accel;
iv = 1 / Length(V);
it = FMath:Min(it, brake * accelBrake * ThrustRatio * iv);
Accel -= it * V;
/* Apply Jump Jets */
if (Jump)
{
Accel += accelJump * ThrustRatio * Up;
}
/* Apply Steering Controls */
/* Pitch with pitch and thrust */
if (Throttle > 1)
{
Throttle = (Throttle - 1.0f) * 0.5f + 1.0f;
Alpha.y += AlphaTrack * PitchPitch * pitch - ScaledTrack * PitchThrust * Throttle;
}
/* Roll with Strafing */
Alpha.x += ScaledTrack * RollStrafe * Strafe;
/* Yaw with Steer */
float TurnRate = OmegaSpin + (OmegaTurn - OmegaSpin) * ControlMag;
if (TurnRate > 0)
{
Alpha.Z = AlphaSteer * FMath::Clamp(Steer - Omega.Z / TurnRate, -1.0f, 1.0f);
}
else
{
Alpha.Z = 0.0f
}
/* Apply Wind Resistance */
Accel -= 0.01 * Length(Veloc) * Veloc;
}