83 - Correcting the Weapon Rotation

This commit is contained in:
Kingsmedia 2022-05-05 20:14:17 +02:00
parent afa339d8c1
commit ad7af7454b
7 changed files with 33 additions and 1 deletions

View File

@ -58,11 +58,18 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
if (bWeaponEquipped && EquippedWeapon && EquippedWeapon->GetWeaponMesh() && BlasterCharacter->GetMesh())
{
LeftHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("LeftHandSocket"), ERelativeTransformSpace::RTS_World);
LeftHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("LeftHandSocket"), RTS_World);
FVector OutPosition;
FRotator OutRotation;
BlasterCharacter->GetMesh()->TransformToBoneSpace(FName("hand_r"), LeftHandTransform.GetLocation(), FRotator::ZeroRotator, OutPosition, OutRotation);
LeftHandTransform.SetLocation(OutPosition);
LeftHandTransform.SetRotation(FQuat(OutRotation));
if (BlasterCharacter->IsLocallyControlled())
{
bLocallyControlled = true;
const FTransform RightHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("Hand_R"), RTS_World);
RightHandRotation = UKismetMathLibrary::FindLookAtRotation(RightHandTransform.GetLocation(), RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BlasterCharacter->GetHitTarget()));
}
}
}

View File

@ -66,4 +66,10 @@ private:
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
ETurningInPlace TurningInPlace;
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
FRotator RightHandRotation;
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
bool bLocallyControlled;
};

View File

@ -323,6 +323,13 @@ AWeapon* ABlasterCharacter::GetEquippedWeapon()
return Combat->EquippedWeapon;
}
FVector ABlasterCharacter::GetHitTarget() const
{
if (Combat == nullptr) return FVector();
return Combat->HitTarget;
}
void ABlasterCharacter::OnRep_OverlappingWeapon(AWeapon* LastWeapon)
{
if (OverlappingWeapon)

View File

@ -76,4 +76,5 @@ public:
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; };
AWeapon* GetEquippedWeapon();
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; };
FVector GetHitTarget() const;
};

View File

@ -43,6 +43,13 @@ void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
SetHUDCrosshairs(DeltaTime);
if (Character && Character->IsLocallyControlled())
{
FHitResult HitResult;
TraceUnderCrosshairs(HitResult);
HitTarget = HitResult.ImpactPoint;
}
}
void UCombatComponent::SetHUDCrosshairs(float DeltaTime)
@ -167,6 +174,8 @@ void UCombatComponent::TraceUnderCrosshairs(FHitResult& TraceHitResult)
End,
ECollisionChannel::ECC_Visibility
);
if (!TraceHitResult.bBlockingHit) TraceHitResult.ImpactPoint = End;
}
}

View File

@ -69,4 +69,6 @@ private:
float CrosshairVelocityFactor;
float CrosshairInAirFactor;
FVector HitTarget;
};