Hi, currently I’m making a grappling hook when I prespawn the hook in front of my gun, shoot it, add velocity, hit something, stop or if it gone too far it will retract back.
The hook works perfectly if I didnt hit anything, the codes below.
void AGrapplingHook::AddVelocityToBullet()
{
StaticMeshComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
ProjectileMovementComponent->SetVelocityInLocalSpace(FVector(BulletMovementSpeed, 0, 0));
}
However, SetVelocityinLocalSpace stop working if I retracted the hook from a wall. Is there anyway I can set velocity multiple time?
I tried doing it in blueprint but the velocity still stays 0,0,0 after I have retracted the hook from the wall.
Here’s the code for retract:
void AGrapplingHook::RetractHook(float DeltaTime)
{
if (!IsValid(GetOwner())) { return; }
ProjectileMovementComponent->SetVelocityInLocalSpace(FVector::ZeroVector);
FTransform SpawnpointTransform = GetSpawnPointTransform();
FVector LerpedLocation = UKismetMathLibrary::VLerp(GetActorLocation(), SpawnpointTransform.GetLocation(), DeltaTime * 30.0f);
SetActorLocationAndRotation(LerpedLocation, SpawnpointTransform.GetRotation());
float DistanceBetweenHookAndPlayer = UKismetMathLibrary::VSize(GetActorLocation() - SpawnpointTransform.GetLocation());
if (UKismetMathLibrary::NearlyEqual_FloatFloat(DistanceBetweenSuctionCupAndPlayer, 0.0f, 0.5f))
{
AGun* Gun= Cast<AGun>(GetOwner());
AttachToComponent(Ranged->GetSkeletalMesh(), FAttachmentTransformRules::KeepWorldTransform, Ranged->ShootSocket);
bIsRetractHook = false;
}
}