Can the game only accept one AddActorWorldOffset() per tick?

anonymous_user_5e132e2c
Wed, 07 Nov 2018 06:00:54 +0000
World Creation

I wrote a moving platform with the following code:

void AMovingPlatformActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	///move if not reached full distance or wall.
	if (LastStopTime + WaitTime < GetWorld()->GetTimeSeconds())
	{

		if (((LastStoppedPosition - GetActorLocation()).SizeSquared() >= MoveDistance * MoveDistance) || bWallHit)
		{
			TranslationDirection = TranslationDirection * -1.0f;
			LastStopTime = GetWorld()->GetTimeSeconds();
			LastStoppedPosition = GetActorLocation();
			bWallHit = false;
		}
		FHitResult* PlatformHit = new FHitResult(ForceInit);
		AddActorWorldOffset(DeltaTime * MoveSpeed * TranslationDirection, true, PlatformHit);
		AActor* HitActor = PlatformHit->GetActor();
		if (PlatformHit->IsValidBlockingHit())
		{
			//force move platform
		AddActorWorldOffset(DeltaTime * MoveSpeed * TranslationDirection, false);
		}
	}
}

To summarize this code: First call AddActorWorldOffset() with sweep. Then if there is a hit, call it again without sweep. This platform will not go through objects even though the second time AddActorWorldOffset() is called, it is without sweep.

Then I compared it to a simplified version:

   void AMovingPlatformActor::Tick(float DeltaTime)
    {
    	Super::Tick(DeltaTime);

    	///move if not reached full distance or wall.
    	if (LastStopTime + WaitTime < GetWorld()->GetTimeSeconds())
    	{

    		if (((LastStoppedPosition - GetActorLocation()).SizeSquared() >= MoveDistance * MoveDistance) || bWallHit)
    		{
    			TranslationDirection = TranslationDirection * -1.0f;
    			LastStopTime = GetWorld()->GetTimeSeconds();
    			LastStoppedPosition = GetActorLocation();
    			bWallHit = false;
    		}
    		//force move platform
		AddActorWorldOffset(DeltaTime * MoveSpeed * TranslationDirection, false);
    	}
    }

This code only calls AddActorWorldOffset once, without the sweep. This platform will go through walls, floor, etc. but not the player Character, which it bumps.

What’s going on here?

Note that this is a simplified version of my code, but still the one I am currently testing with; the original functionality was to change direction at walls and bump player characters that were hit, but I found the player character was still somehow blocking the platform and making it fall behind (the timing of platforms is important for my game). Also: yes I know how I should use a timer, that’s the next thing I’ll implement, I swear it!

2 posts - 1 participant