Hi.
I want spawn a bullet(projectile) in a socket place . but it doesent happen and it spawn in different position near the socket ( may near the skeletal mesh).
void APlayerCharacter::Fire()
{
if (bulletClass != NULL)
{
FVector spawnLocation;
FRotator spawnRotation;
firstPersonSkeletalMesh->GetSocketWorldLocationAndRotation("FirePlaceSocket", spawnLocation, spawnRotation);
UWorld* world = GetWorld();
ABullet* bullet = world->SpawnActor<ABullet>(bulletClass, spawnLocation, spawnRotation);
}
firstPersonSkeletalMesh->PlayAnimation(fireAnimation, false);
}
It have problem ?
I put a socket in front of weapon;
thanks
http://www.axgig.com/images/23699589451274638182.png
eXi
(Cedric Neukirchen)
August 31, 2014, 11:44am
2
Have you tested if the socket is in the right position? You can add the
projectile to the Socket in the Mesh Editor (where you created the socket).
Maybe it’s a bit offset.
yes. can put a picture from it in first post now
Virusik
(ŁukaszSiergiej)
August 31, 2014, 6:02pm
4
const FRotator SpawnRotation = FRotationMatrix::MakeFromX(Location - Weapon->GetSocketLocation(FName(TEXT(“MuzzleFlashSocket”)))).Rotator();
const FVector SpawnLocation = Weapon->GetSocketLocation(FName(TEXT(“MuzzleFlashSocket”)));
UWorld* const World = GetWorld();
if (World != NULL)
{
World->SpawnActor(ProjectileClass, SpawnLocation, SpawnRotation);
}
I am calculating rotation form hit point location (Line Trace) - socket rotation. Alwsa if u wanna add smth to socket u should use deffered atachment:
Flashlight = PCIP.CreateDefaultSubobject<USpotLightComponent>(this, TEXT("FlashLight"));
Flashlight->AttachParent = Weapon;
Flashlight->AttachSocketName = FName(TEXT("MuzzleFlashSocket"));
Alwso your are spawnning bullet which has collsion on itself so probably that cause your bullet to sapwn next to weapon. U can adapt it to your needs.