haxis/Source/UnrealProject/Abilities/SpiralProjectile.cpp

35 lines
975 B
C++

// Project Lab - NHTV Igad
#include "UnrealProject.h"
#include "NetworkCharacter.h"
#include "SpiralProjectile.h"
#define SPIRALTIMESTEP (0.02f)
void ASpiralProjectile::BeginPlay()
{
Super::BeginPlay();
if (Role != ROLE_Authority)
return;
// Set the rotation of the projectile so that it is facing away from the caster.
SetActorRotation(FRotator((this->GetActorLocation() - character->GetActorLocation()).Rotation()));
m_elapsedTime = 0;
}
void ASpiralProjectile::NativeMove(float DeltaTime)
{
m_elapsedTime += DeltaTime;
// Fixed update
while (m_elapsedTime >= SPIRALTIMESTEP)
{
m_elapsedTime -= SPIRALTIMESTEP;
float distance = speed * SPIRALTIMESTEP;
// Rotate the projectile according to how far it has traveled.
FRotator rotation = FRotator(0, distance * 0.25f, 0);
AddActorWorldRotation(rotation);
// Move the projectile forwards.
AddActorWorldOffset(GetActorForwardVector() * (distance * 2), true);
}
}