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"

Ignoring collision for a certain object in C++

Hey! I am working on the projectile script that comes with the first person starter project. What I am trying to do is I am trying to get the projectile to ignore collision from a certain object (as it destroys itself as soon as it detects a UComponent). Anyone know what I can do to prevent this from happening? I already made my own little attempt, where the projectile checks what type of class the actor is running on, but I am not sure how I should implement it.

 void AFirstPersonProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
 {
     if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
     {
         if (OtherActor->GetActorClass() != ACollectable) /**if the ActorClass is equal to "ACollectable", one of my classes*/
         {
         OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
 
         Destroy();
         }
     }
 }

As always, I appreciate any feedback. Thank you in advance!

Product Version: Not Selected
Tags:
more ▼

asked May 03 '14 at 05:40 PM in C++ Programming

avatar image

Borzi
174 43 39 47

avatar image BiggestSmile May 03 '14 at 06:12 PM

You should replace your checking line with the following one:

 if(OtherActor->IsA(ACollectable::StaticClass()))
 {
     AddImpulse();
     Destroy();
 }

Should work like that.

avatar image Borzi May 03 '14 at 07:21 PM

So how would I rewrite it if I did NOT want the Actor to be of that class?

 OtherActor->IsA(ACollectable::StaticClass(false)) //?
avatar image BiggestSmile May 03 '14 at 07:40 PM

Oh sorry, a typo there :) Rama fixed code below.

avatar image Rama May 03 '14 at 07:42 PM

awesome sharing BiggestSmile!

:)

Rama

avatar image Borzi May 03 '14 at 07:43 PM

So why isn't BiggestSmile allowed to post it as an answer?

avatar image BiggestSmile May 03 '14 at 07:45 PM

I am able; didn't do so because was not sure it was what you were looking for exactly, just mark Rama's answer :)

avatar image Borzi May 03 '14 at 07:46 PM

Okay sure, if you are alright with it.

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

1 answer: sort voted first

Solution

 if( ! OtherActor->IsA(ACollectable::StaticClass()))
 {
     AddImpulse();
     Destroy();
 }

(credit to Biggest Smile too but I am posting an answer post)

more ▼

answered May 03 '14 at 07:33 PM

avatar image

Rama
10.6k 446 343 1085

avatar image Borzi May 03 '14 at 07:40 PM

Works, thank you very much!

(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