Whenever the player shoots bullets, I cause them to move forward for 0.2 seconds and then break left 90 degrees. I am just testing how I can change bullet behavior mid flight. The problem is that they break left at different times. I was expecting them to break left at the same point on the screen as long as the player ship never moved.
Here is what happens in the bullet’s tick:
##Bullet.h
void ABullet::Tick(float DeltaTime)
{
// Behavior is an ABulletBehavior object that handles bullet movement
Behavior->DeltaSeconds = DeltaTime;
Behavior->StraightAndBreak();
}
##BulletBehavior.h
void ABulletBehavior::GoStraight()
{
MyBullet->AddActorLocalOffset(FVector((BulletSpeed * DeltaSeconds), 0.f, 0.f));
}
void ABulletBehavior::StraightAndBreak()
{
GoStraight();
if (!bDidBreak)
{
GetWorldTimerManager().SetTimer(this, &ABulletBehavior::Break, 0.2, false);
bDidBreak = true;
}
}
void ABulletBehavior::Break()
{
MyBullet->AddActorLocalRotation(FRotator(0.f, -90.f, 0.f));
}
Here is a video of the problem. There are enemies spawning off screen to simulate more load on the game. That is why the frame rate varies:
I definitely need more precise control over when and where bullet movement changes but I’m not sure what I can do.