Hi, how are you guys doing?
I’m a begginer to UE4 and I would like to make some questions, if you don’t mind.
I’m making an Arkanoid game and I decided to make my own CollisionChannels to better understand my code. I went to Project Settings → Engine → Collision and created some under Object Channels. On my ball, trought the aid of the function SweepResult.GetComponent()->GetCollisionObjectType(), inside of the OnComponentBeginOverlap() delegate function, I’ve got the integer return value as ball hitted the wall, the screen border, the blocks and itself.
int test = SweepResult.GetComponent()->GetCollisionObjectType(); UE_LOG(LogTemp, Warning, TEXT("CollisionChannel Type: %d."), test);
With that, I’ve noted that:
Paddle is 14.
Ball is 15.
Block_SM is 16.
ScreenBorder is 17.
Note the integer values above is what I’ve got trought the pointview of the ball, as the ball hitted those objects. With the information of hovering my mouse on the ECC_GameTraceChannels in the EngineTypes.h, I’ve made this defines on the top of the .cpp of the files that I deal with collision:
#define ECC_Paddle ECC_GameTraceChannel1 #define ECC_Ball ECC_GameTraceChannel2 #define ECC_BlockSM ECC_GameTraceChannel3 #define ECC_ScreenBorder ECC_GameTraceChannel4
Now in the OnComponentBeginOverlap() of the Block, I’ve made this:
int test = SweepResult.GetComponent()->GetCollisionObjectType(); if(test == 15) UE_LOG(LogTemp, Warning, TEXT("Block: I was hitted by the ball."));
This if statement doesn’t trigger when the block is hitted by the ball. With some effort, I have made two blocks collide and value returned by
int test = SweepResult.GetComponent()->GetCollisionObjectType(); UE_LOG(LogTemp, Warning, TEXT("Block: %d."), test);
was 16 when the block was hitted by another block. When the block was hitted by the ball I’ve got the same value: 16. I would like to know some fix or workaround for this.
Sometimes the ball collides with two things in the same frame. I’ve detected this using the GFrameNumber global variable and other boolean to know this. It worked and its quite normal. So, some problems are happening because too many collision are happening in quick sucession or together. I would like to know if I can only process the ScreenBorder collision and ignore the others.
As my game is "2D’, I’m trying to make my collision 2D as well for performace. I’m giving the Paddle and the Block UBoxComponent made for collision with the Y value at 0.0f in the Box Extent FVector. With my ScreenBorder, it’s two UBoxComponent with 0.0f scale applied to X and Y rooted to a empty USceneComponent. As I hit play, I get this from the log. I tried to disable everything related to physics.
LogPhysics: Warning: Scale for /Engine/Transient.World_10:PersistentLevel.ScreenBorderCollision_BP_C_0.Left Side has a component set to zero, which will result in a bad body instance. Scale:X=0.000 Y=0.000 Z=200.000
I get one for the Right Side too. Is this aproach going to a problem? If so, what do you guys sugest?
Whow, I think I’m done. Sorry for this.
Thanks so much for reading trough this.