Hello,
I have my character, who is the owner of the weapon item which has a socket callled Fire_Position. This is where the projectile is supposed to be launched from. From what I understand GetSocketLocation() should return the position of that socket in world space where i can then spawn the projectile. But what has happened is it is giving me the location of the socket relative to the skeletal mesh bone of the weapon. I have no idea why it is happening. Here is my code:
FActorSpawnParameters params;
params.Owner = this;
params.Instigator = Instigator;
AAmmunitionItem* projectile = GetWorld()->SpawnActor<AAmmunitionItem>(item->projectile, item->Mesh->GetSocketLocation(FName("Fire_Position")), item->GetActorRotation(), params);
EDIT:
After additional testing, it turns out I can get world location of the socket from other places within the code. I cannot however get it within my firing function, which is where i specifically spawn the projectile. I do not know whether this is a bug, or maybe there is something that is keeping it from giving me the correct coordinates.
EDIT 2:
So set a FVector in the tick function and it would continually update with the correct coordinates. But as soon as I checked that Vectore from the Fire() function it would return at the wrong coordinates.
I will post the whole code so maybe it will give some insight:
void APlayerCharacter::OnLeftMouse() {
if (Inventory->Equipped[0] != NULL) {
AItemBase* i = Inventory->Equipped[0]->Base;
if (i->tag == EItemTag::Usable) {
if (i->IsA(AUsableItem::StaticClass())) {
AUsableItem* j = Cast<AUsableItem>(i);
if (j->uTag == EUsableTag::Ranged) {
if (j->IsA(ARangedWeapon::StaticClass())) {
ARangedWeapon* k = Cast<ARangedWeapon>(j);
Fire(k);
}
}
}
}
}
}
void APlayerCharacter::Fire(ARangedWeapon* item) {
if (item->projectile->IsChildOf(AAmmunitionItem::StaticClass())) {
FActorSpawnParameters params;
params.Owner = this;
params.Instigator = Instigator;
AAmmunitionItem* projectile = GetWorld()->SpawnActor<AAmmunitionItem>(item->projectile, ActorToWorld().TransformPosition(item->firePosition), item->GetActorRotation(), params);
}
}
Any help is appreciated,