Landscape Collision Error (Objects go through landscape)

Did you make any other changes? Because I tested it with what you gave me and it works as expected.

I know that one I gave you was working correctly.
I did not use GetSafeNormal with Direction.

But I made some changes in the function of ReGuidingMissile that shown in code above. The main change was by adding GetSafeNormal and unfortunately it made illogical behavior.

I was asking if you had made any other changes to the code. Because I had applied the changes you gave in that post and it worked fine.

With that said I suspect you are using Visual Studio 16.3 which has code gen bugs which will effect GetSafeNormal. You need to update Visual Studio.

Ohh !! I remembered, yes i made some changes :slight_smile:
Original Code before changes was:

void AMissileActor::ReGuidingMissile()
{
	if(!FrontPartOfMissile) return;
	
	if(LauncherPlayerController->Hit.GetActor() != this)
	{
		FrontPartOfMissile->SetWorldRotation(LauncherPlayerController->Crosshair_3D_Direction.Rotation());

		FVector TargetLocation = LauncherPlayerController->Hit.Location;
		auto MissileLocation = FrontPartOfMissile->GetComponentLocation();
		auto DeltaRotation = (TargetLocation - MissileLocation).Rotation();

		if(FMath::Abs(DeltaRotation.Yaw) <= MaxAngleOfMissileRotation && FMath::Abs(DeltaRotation.Pitch) <= MaxAngleOfMissileRotation)
		{
			FrontPartOfMissile->SetWorldRotation( DeltaRotation );
		}
	}
}

The new code is:

void AMissileActor::ReGuidingMissile(float DeltaTime)
{
	if(LauncherPlayerController->Hit.GetActor() != this)
	{
		FVector TargetLocation = LauncherPlayerController->Hit.Location;
		FVector MissileLocation = FrontPartOfMissile->GetComponentLocation();

        // GetSafeNormal has been used here to get the direction..
		auto Direction = (TargetLocation - MissileLocation).GetSafeNormal();

		FRotator TargetDirectionRotation = Direction.Rotation();
		FRotator MissileForwardRotation = FrontPartOfMissile->GetForwardVector().Rotation();
		FRotator DeltaRotation = (TargetDirectionRotation - MissileForwardRotation);
		
		if(FMath::Abs(DeltaRotation.Yaw) <= DirectionChangingMaxAngle && FMath::Abs(DeltaRotation.Pitch) <= DirectionChangingMaxAngle){
			FRotator MissileNewRotation = FrontPartOfMissile->GetComponentRotation() + (DeltaRotation * DeltaTime * FMath::Clamp<float>(DirectionChangingSpeed, 1, 6));
			FrontPartOfMissile->SetWorldRotation( MissileNewRotation );
		}
	}	
}

That’s right the version i had was 16.3.6 so i updated that to the latest one …
11
The missile are working correctly now after this updating Thanks @DanM

On the same context, i am using tanks and turrets and barrels that should aim to my pawn but there is an error in that… [ Look to my video ] please :slight_smile:

The code based on that problem is:

void UAimingActorComponent::AimToMainPlayer(float DeltaTime)
{
	FVector TargetLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
	FVector BarrelLocation = Barrel->GetComponentLocation();
	auto Direction = (TargetLocation - BarrelLocation).GetSafeNormal();

	FRotator BarrelRotation = Barrel->GetForwardVector().Rotation();
	FRotator DirectionRotation = Direction.Rotation();
	FRotator DeltaRotation = (DirectionRotation - BarrelRotation);

	DrawDebugLine(GetWorld(), BarrelLocation, BarrelLocation + Direction * 200000, FColor::Blue, false, 0, 0, 10);
	TurretAimToTarget(DeltaRotation, DeltaTime);
	BarrelAimToTarget(DeltaRotation, DeltaTime);
}
void UAimingActorComponent::TurretAimToTarget(FRotator DeltaRotation, float DeltaTime)
{
	auto TurretRotatingAngle = Turret->GetComponentRotation().Yaw + (DeltaRotation.Yaw * DeltaTime);
	Turret->SetRelativeRotation(FRotator(0, TurretRotatingAngle, 0));
}

void UAimingActorComponent::BarrelAimToTarget(FRotator DeltaRotation, float DeltaTime)
{
	auto BarrelElevatingAngle = Barrel->GetComponentRotation().Pitch + (DeltaRotation.Pitch * DeltaTime);

	if(BarrelElevatingAngle >= MinBarrelElevationAngle && BarrelElevatingAngle <= MaxBarrelElevationAngle)
		Barrel->SetRelativeRotation(FRotator(BarrelElevatingAngle, 0, 0));
}

Do you not use source control? Because it would be much easier for me to help you.

What is that ? How can I use it?

AKA version control.

It’s used to track changes a popular one is called git. The Unreal C++ Course goes over it though there is now a course on it by GameDev.tv.

On GameDev.tv:
https://www.gamedev.tv/p/git-smart-course
Or Udemy, if you prefer:
https://www.udemy.com/course/git-smart-learn-git-the-fun-way-with-unity-games/

Mr @DanM now my project is on Github platform, and still the problem existing …
https://github.com/mkscit/Anti-Tank-Guided-Missile

You have a circular dependency which you should resolve
2020-01-04 11_45_09-MINGW64__e_Projects_Repos_Unreal_Anti-Tank-Guided-Missile

With that said it seems fine on my end. I would suggest you rebuild your project.

Unfortunately, The problem still existing
I note something strange … if we left the local direction of the tank in the same direction of the World then it will work fine, but if we rotate the local direction of tank a little bit according to World it makes that error behavior.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms