Hello guys.
I attach a box component to my character, im trying to make the box moves it’s position when i press an attack button. The problem is, the box only change it’s position when my character is moving no when i press the button. I don’t know if is a render problem because the transform values change but the box is not rendering it’s new position until my character is moving.
the box is attached to rootcomponent.
Here is my code:
Constructor:
SwingCollisionR = CreateDefaultSubobject<UBoxComponent>(TEXT("Trigger Component"));
SwingCollisionR->AttachTo(RootComponent);
SwingCollisionR->SetRelativeLocation(FVector::ZeroVector);
SwingCollisionR->bGenerateOverlapEvents = true;
SwingCollisionR->SetCollisionResponseToAllChannels(ECR_Overlap);
SwingCollisionR->OnComponentBeginOverlap.AddDynamic(this, &AExa2Character::Hit);
Here is where i change the box position
void AExa2Character::Swing()
{
if (!bhit)
{
SwingCollisionR->RelativeLocation.X = SwingCollisionR->RelativeLocation.X + fAttackRange;
}
bhit = true;
}
My Tick Function
void AExa2Character::Tick(float deltatime)
{
Super::Tick(deltatime);
if (bhit)
{
fHitDurationTime -= deltatime;
if (fHitDurationTime <= 0)
{
bhit = false;
fHitDurationTime = fHitDurationTimeDefault;
FVector ActorLocation = GetActorLocation();
SwingCollisionR->RelativeLocation.X = SwingCollisionR->RelativeLocation.X - fAttackRange;
}
}
}