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"

Question regarding Character to Character collision

Hey there. I'm trying to implement a sort of melee clash system where two characters who collide with each other will sort of clash and whoever wins the clash will perform an attack. The clash winner is determined by their current melee stance at the moment of impact. It's kind of like a rock paper scissors where stance A beats stance B, stance B beats stance C, stance C beats stance A. If both characters are on the same stance the clash results in a draw.

Anyway I'm overriding NotifyHit so that I can catch the event when the two characters collide with one another. Basically I want to evaluate the winner of the clash within this event by retrieving the melee stance of character A and character B (the other actor) and applying the rock paper scissors rule. I have it implemented like so:

 void AFighterCharacter::NotifyHit(
          class UPrimitiveComponent* MyComp, 
          AActor* OtherActor, 
          class UPrimitiveComponent* OtherComp, 
          bool bSelfMoved, 
          FVector HitLocation, 
          FVector HitNormal, 
          FVector NormalImpulse, 
          const FHitResult& Hit)
 {
     if (OtherActor && (OtherActor != this) && OtherComp)
     {
         TargetedEnemy = Cast<AFighterCharacter>(OtherActor);
         if (TargetedEnemy && !TargetedEnemy->IsLockedInMelee() && !IsLockedInMelee())
         {
             bLockedInMelee = true;
 
             ClashResult = ProcessMeleeClash(TargetedEnemy->GetMeleeStance());
 
             GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Blue, "" + ClashResult);
         }
     }
 }

So the idea here is to lock both players until the clash is resolved so that other players cannot initiate a new clash with either one of them. ProcessMeleeClash then returns an int32 value which is either 0 = LOSE, 1 = WIN, 2 = DRAW.

When I test this, the character I'm controlling who collides with a stationary character gets tagged successfully as the winner (i.e. ClashResult = 1) and that will cause the animation instance to play the corresponding melee animation since it sees that he is the winner.

My problem is that I was expecting the other character to get a ClashResult of 0 since he lost the clash, so that his animation instance would play a different animation to react to the melee animation played by the winning character, but it appears that the NotifyHit event only triggers on the character that was moving towards the stationary character as I'm only seeing a ClashResult of 1 on screen (Debug Message logged).

By the way, the following variables are replicated:

 // Replicate to clients
 DOREPLIFETIME(AFighterCharacter, MeleeStance);
 DOREPLIFETIME(AFighterCharacter, bLockedInMelee);
 DOREPLIFETIME(AFighterCharacter, TargetedEnemy);

Perhaps it's a replication issue and I may be doing something wrong on the way I'm approaching this. Any ideas? I can provide more information if needed.

Product Version: UE 4.8
Tags:
more ▼

asked Jul 18 '15 at 08:54 PM in C++ Programming

avatar image

Bluarchon
13 2 5 10

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

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