Skip to content

Commit

Permalink
BT83 Improving Tank Aiming.cmproj
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tristem committed Jul 23, 2016
1 parent fa5baeb commit d06b8d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Binary file modified BattleTank/Content/Tank/Tank_BP.uasset
Binary file not shown.
Binary file modified BattleTank/Content/_Levels/BattleGround.umap
Binary file not shown.
10 changes: 9 additions & 1 deletion BattleTank/Source/BattleTank/Private/TankAimingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection)
auto AimAsRotator = AimDirection.Rotation();
auto DeltaRotator = AimAsRotator - BarrelRotator;

// Always yaw the shortest way
Barrel->Elevate(DeltaRotator.Pitch);
Turret->Rotate(DeltaRotator.Yaw);
if (DeltaRotator.Yaw < 180)
{
Turret->Rotate(DeltaRotator.Yaw);
}
else
{
Turret->Rotate(-DeltaRotator.Yaw);
}
}

void UTankAimingComponent::Fire()
Expand Down
8 changes: 4 additions & 4 deletions BattleTank/Source/BattleTank/Private/TankPlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void ATankPlayerController::AimTowardsCrosshair()
if (!ensure(AimingComponent)) { return; }

FVector HitLocation; // Out parameter
if (GetSightRayHitLocation(HitLocation)) // Has "side-effect", is going to line trace
bool bGotHitLocation = GetSightRayHitLocation(HitLocation);
if (bGotHitLocation) // Has "side-effect", is going to line trace
{
AimingComponent->AimAt(HitLocation);
}
Expand All @@ -45,10 +46,9 @@ bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const
if (GetLookDirection(ScreenLocation, LookDirection))
{
// Line-trace along that LookDirection, and see what we hit (up to max range)
GetLookVectorHitLocation(LookDirection, HitLocation);
return GetLookVectorHitLocation(LookDirection, HitLocation);
}

return true;
return false;
}

bool ATankPlayerController::GetLookVectorHitLocation(FVector LookDirection, FVector& HitLocation) const
Expand Down

0 comments on commit d06b8d1

Please sign in to comment.