Hi. I am trying to do a weapon and projectile programming. But I am getting a weird Skeletal Mesh Socket location and rotation.
It seems the location of the socket doesn’t include my character’s or attached weapon’s rotation. But rotation and location seems to include animation (In the picture below the red line animating with the characters idle animation but it always directing the same direction it is not including my character’s rotation but it includes my character’s location.).
Here is the results:
Here is my draw debug line code on Weapon Actor class. Note: SkeletalMesh of Weapon Actor is root component and the bCanEverTick for it’s PrimaryActor also enabled.
void AFireArm::Tick(float DeltaSeconds)
{
// ...
DrawDebugLine(GetWorld(), SkeletalMesh->GetSocketLocation("Muzzle"), SkeletalMesh->GetSocketLocation("Muzzle") + SkeletalMesh->GetSocketRotation("Muzzle").Vector() * 5000.0F, FColor::Red);
const USkeletalMeshSocket* socket = SkeletalMesh->GetSocketByName("Muzzle");
if (socket)
{
GEngine->AddOnScreenDebugMessage(1, 1, FColor::Red, "Socket Valid");
}
}
I have attached the weapon like this:
void APlayerCharacter::BeginPlay()
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
AFireArm* FireArm = GetWorld()->SpawnActor<AFireArm>(DefaultFireArm, SpawnParams);
if (FireArm)
{
FireArm->AttachRootComponentTo(Mesh, "WeaponSocket", EAttachLocation::SnapToTarget);
FireArms.Add(FireArm);
CurrentFireArm = FireArm;
}
}
Finally this is the socket for the weapon:
What is wrong with the code. Can you help me?