I’ll attach relevant code at the bottom of this post, but essentially my pawn isn’t reacting to collision at all. It’s set up with a camera + boom, a cubic mesh with disabled collision, and a UBoxComponent fitted to the mesh for collision purposes.
The object I want to collide has a custom collision preset known as worldActor, while the other object has preset worldGeometry. Both are set to ignore all collision channels except for each other-- they block one another. I’d look at this setup for a problem if I hadn’t already been having the issue before implementing this.
I’ve tried to test to see if any collision is detected at all, by destroying the pawn on collision or disabling movement, to no avail. Thus, I’ve determined that I’m missing something concerning IsValidBlockingHit() in my JumperMovement class.
My pawn spawns in the world moving forward and right, diagonally, hence the “xyzSpeed” FVector. Take a look. (If there’s any way to make these code blocks collapsible, I’m sorry for being unaware.)
Jumper.h
#pragma once
#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/Pawn.h"
#include "JumperMovement.h"
#include "Jumper.generated.h"
UCLASS()
class PLATFORMER_API AJumper : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AJumper();
UPROPERTY(EditAnywhere)
UBoxComponent* boundBox;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* staticMesh;
UPROPERTY(VisibleAnywhere)
USpringArmComponent* springBoom;
UPROPERTY(VisibleAnywhere)
UCameraComponent* springCamera;
UJumperMovement* movementComponent;
FVector xyzSpeed = FVector(10.0f, 10.0f, 0.0f);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
Jumper.cpp
#include "Jumper.h"
#include "Runtime/CoreUObject/Public/CoreUObject.h"
// Sets default values
AJumper::AJumper()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 3.0f));
boundBox = CreateDefaultSubobject<UBoxComponent>(TEXT("boundBox"));
boundBox->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
boundBox->SetWorldScale3D(FVector(1.57f, 1.57f, 1.57f));
boundBox->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
boundBox->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
boundBox->SetCollisionProfileName(TEXT("Custom"));
boundBox->SetCollisionObjectType(ECC_GameTraceChannel1);
boundBox->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
boundBox->SetCollisionResponseToChannel(ECC_GameTraceChannel2, ECollisionResponse::ECR_Block);
springBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("springBoom"));
springBoom->SetupAttachment(RootComponent);
springBoom->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 80.0f), FRotator(-10.0f, 0.0f, 0.0f));
springBoom->TargetArmLength = 500.0f;
springBoom->bEnableCameraLag = true;
springBoom->bEnableCameraRotationLag = true;
springBoom->CameraLagSpeed = 5.0f;
springBoom->CameraRotationLagSpeed = 5.0f;
springBoom->CameraLagMaxDistance = 0.0f;
springCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("springCamera"));
springCamera->SetupAttachment(springBoom, USpringArmComponent::SocketName);
springCamera->bUsePawnControlRotation = false;
staticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("staticMesh"));
staticMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
staticMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
static ConstructorHelpers::FObjectFinder<UStaticMesh> cubeTestMesh(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (cubeTestMesh.Succeeded())
{
staticMesh->SetStaticMesh(cubeTestMesh.Object);
}
movementComponent = CreateDefaultSubobject<UJumperMovement>(TEXT("UJumperMovement"));
movementComponent->UpdatedComponent = RootComponent;
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void AJumper::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AJumper::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
movementComponent->speedVector = xyzSpeed;
/*FVector deltaMove = GetActorLocation();
deltaMove.X += xSpeed;
deltaMove.Y += ySpeed;
deltaMove.Z += zSpeed;
SetActorLocation(deltaMove);*/
}
// Called to bind functionality to input
void AJumper::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
JumperMovement.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PawnMovementComponent.h"
#include "JumperMovement.generated.h"
/**
*
*/
UCLASS()
class PLATFORMER_API UJumperMovement : public UPawnMovementComponent
{
GENERATED_BODY()
public:
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
FVector speedVector = FVector(0.0f, 0.0f, 0.0f);
};
JumperMovement.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "JumperMovement.h"
void UJumperMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FHitResult collideResult(1.f);
TGuardValue<EMoveComponentFlags> ScopedFlagRestore(MoveComponentFlags, MoveComponentFlags | MOVECOMP_NeverIgnoreBlockingOverlaps);
if (!collideResult.IsValidBlockingHit())
{
SafeMoveUpdatedComponent(speedVector, UpdatedComponent->GetComponentRotation(), true, collideResult);
}
else if (collideResult.IsValidBlockingHit())
{
HandleImpact(collideResult, DeltaTime, speedVector);
SlideAlongSurface(speedVector, collideResult.Time - 1, collideResult.Normal, collideResult);
}
}