Hi all,
for my game, I want my character can activate an aura that gives a bonus to the characters within a certain radius.
Obviously, the bonus is removed if they leave my aura.
Do you have ideas or best practices to do this ?
Thanks
Hi all,
for my game, I want my character can activate an aura that gives a bonus to the characters within a certain radius.
Obviously, the bonus is removed if they leave my aura.
Do you have ideas or best practices to do this ?
Thanks
Nobody has any idea ?
Hi, hope you can understand my English.
You can add a sphere collition component in your character BP that generate overlap events.
So when other actor enter the sphere, you can apply the “aura” with begin overlap event and when the actor leaves the sphere you can turn off the “aura” with End overlap event.
Mmmh, I want do that in C++, not in Blueprint :/.
hmm yes i did not realise the subforum, i’m sorry
see this link:
Specially:
/** sphere component */
UPROPERTY(VisibleAnywhere, Category = "Switch Components")
class USphereComponent* Sphere1;
then, declare OnOverlapBegin and OnOverlapEnd, the functions that will be called when another Actor enters or leaves the SphereComponent.
/** called when something enters the sphere component */
UFUNCTION()
void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
/** called when something leaves the sphere component */
UFUNCTION()
void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
and in the ccp file
Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlapBegin); // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlapEnd); // set up a notification for when this component overlaps something
void ALightSwitchCodeOnly::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
ToggleLight();
}
}
void ALightSwitchCodeOnly::OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
ToggleLight();
}
}
check the link for the detailed information and the complete .h and .cpp files (i could explain you here, but with my English I will probably confuse you more :S)
hope it help
Ok thanks I will try this
I think I can’t use it, because it’s just 1 of my characters who have this SphereComponent (the aura). And I want when another character enter in this aura get bonus or lose bonus when he leaves it. So, I can’t use it because all my characters didn’t have a SphereComponent but just 1.
Or maybe I didn’t understand your post ^^
Well only 1 character needs to detect.
If a character has a sphere component, you can detect when any other actor(with collision) enters it or leaves it. You don’t need others to have it.
Another thing you can do which is slightly less efficient but you have a bit more control over it.
You can create a timer which triggers each second which iterates over all types of classes you need
https://wiki.unrealengine.com/Iterators:_Object_%26_Actor_Iterators,_Optional_Class_Scope_For_Faster_Search
Then find the location of those characters which are within an radius and put them in an array and effects to it… Then the next time the timer ticks, you need to check if an actor leaves or enters the array and add effects. Its a bit complicated but if you have multiple auras or you want to make it dynamic. e.g. An item gives the aura then this method is better.