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"

Getting the Forward Vector of a Parent Actor

I'm currently attempted to create a laser beam that will shoot out of this boss that I have, following with it's rotation but currently I can't seem to get it to follow the rotation.

alt text

The Boss will always look at the player as shown in the Image above, with the red lines being where the laser is meant to be following but as you see, they're not actually working with the bosses rotation, they should be pointing directly at the player while coming from the middle of the iris of the eyeball.

This is my code for creating the raycast that I'm using:

 void ALaserBeam::CastRaycast()
 {
     FHitResult* hit = new FHitResult();
     FVector startTrace = laserStart;
     FVector forwardVector = GetParentActor()->GetActorForwardVector();
     FVector endTrace = ((forwardVector * 5000.0f) * startTrace);
     FCollisionQueryParams* traceParms = new FCollisionQueryParams();
 
     if (GetWorld()->LineTraceSingleByChannel(*hit, startTrace, endTrace, ECC_Visibility, *traceParms))
     {
         DrawDebugLine(GetWorld(), startTrace, endTrace, FColor::Red, true);
     }
 
     SetLaserSource(startTrace);
     SetLaserTarget(hit->Location);
 }

The reason I'm doing "GetParentActor()->GetActorForwardVector();" for the Forward Vector variable is cause the laser beam is currently a component of the boss so I want it to get the bosses forward vector instead of it's own (Though I imagine it would work either way as it should rotate with the boss). However as you see, this doesn't work and I'm not really sure how to get it working.

Can anyone help? I'd very much appreciate it

Product Version: Not Selected
Tags:
stupid-images-2.png (207.7 kB)
more ▼

asked May 22 '18 at 12:30 AM in C++ Programming

avatar image

Codelyy
1

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

This line FVector endTrace = ((forwardVector * 5000.0f) * startTrace);

Should be FVector endTrace = ((forwardVector * 5000.0f) + startTrace);

more ▼

answered May 22 '18 at 09:07 AM

avatar image

HarryHighDef
1.3k 1 14 16

(comments are locked)
10|2000 characters needed characters left

add a UArrowComponent to the boss and attach it to his head along his sight.

then get arrow forward vector whenever you need boss forward vector.

more ▼

answered May 22 '18 at 09:37 AM

avatar image

saeedc
2.3k 71 39 102

(comments are locked)
10|2000 characters needed characters left
Your answer
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