Hi,
Just wondering what a good way of getting this would be. Basically, I have an Actor class called Wall that reports back true when it has been hit, and saves it to a bool variable called PositiveHit. What I want to do is take that varibale and use it in an if statement in my main character file. I did some research and found a way to access the actor in another file, using an ActorIterator, however for some reason it only ever reports back one of my walls, rather than all of them. I also imagine I'll need to use casting for this, but I'm not entirely sure of what syntax I would need for it. Any help would be appreciated. Here is the relevant code:
FirstPersonCharacter.cpp
Wall.cpp
This code works perfectly for the one wall, but all the others just don't change the velocity after being hit.
Please excuse me if I've posted wrongly, this is my first time on the forum haha
Thanks in advance!
Just wondering what a good way of getting this would be. Basically, I have an Actor class called Wall that reports back true when it has been hit, and saves it to a bool variable called PositiveHit. What I want to do is take that varibale and use it in an if statement in my main character file. I did some research and found a way to access the actor in another file, using an ActorIterator, however for some reason it only ever reports back one of my walls, rather than all of them. I also imagine I'll need to use casting for this, but I'm not entirely sure of what syntax I would need for it. Any help would be appreciated. Here is the relevant code:
FirstPersonCharacter.cpp
Code:
bool AFirstPersonCharacter::GetHitBool() { for (TActorIterator<AWall> ActorIt(GetWorld()); ActorIt; ++ActorIt) { Wall = *ActorIt; AActor * WallHit = Wall; GLog->Log(*WallHit->GetName()); //weird scenario - literally only mywall3 is being detected in the world at all times. break; } PositiveHit = Wall->PositiveHit; if (PositiveHit == true) { return true; } else (PositiveHit == false); { return false; }; } bool HitBool = AFirstPersonCharacter::GetHitBool(); if (HitBool == true) { VelocityMultiplier = BaseMomentum; } else (HitBool == false); { VelocityMultiplier = VelocityMultiplier * 1.0f; } if (HitBool == true) { HitBool = false; }
Code:
void AWall::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { GLog->Log(*OtherActor->GetName()); PositiveHit = true; } void AWall::Tick(float DeltaTime) { Super::Tick(DeltaTime); frames = frames + 1.0f; //this is setup to make sure the velocitymultiplier starts increasing again afterwards, as there was a bug where it would stay at base forever. if (fmod(frames, 30.f) == 0) { PositiveHit = false; } }
Please excuse me if I've posted wrongly, this is my first time on the forum haha
Thanks in advance!
Comment