x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

ProjectileMovementComponent->SetVelocityInLocalSpace() is not consistent

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? alt text

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;
     }
 }
Product Version: UE 4.22
Tags:
untitled.png (116.6 kB)
more ▼

asked May 06 '19 at 08:16 AM in C++ Programming

avatar image

XynanXDB
3 1 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question