Hi guys.
I am having trouble with adding collision to a object via C++.
I am still new to the programming side of things but I am quickly learning. I have checked the DOCs as well but did not see anything helpful’
Here is my code.
=====
Ground.h file:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “GameFramework/Actor.h”
#include “Ground.generated.h”
UCLASS()
class CPP_IME_API AGround : public AActor
{
GENERATED_BODY()
public:
AGround();
};
Ground.cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include “CPP_IME.h”
#include “Ground.h”
// Sets default values
AGround::AGround()
{
// Create and position a mesh component so we can see where our sphere is
UStaticMeshComponent* GroundVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
GroundVisual->AttachTo(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> GroundVisualAsset(TEXT("/Game/Ground/Ground"));
if (GroundVisualAsset.Succeeded())
{
GroundVisual->SetStaticMesh(GroundVisualAsset.Object);
GroundVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
GroundVisual->SetWorldScale3D(FVector(0.8f));
}
//Adding collision
SetActorEnableCollision(true);
// Our root component will be a sphere that reacts to physics
UBoxComponent* BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent"));
RootComponent = BoxComponent;
BoxComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
BoxComponent->InitBoxExtent(FVector(50.0f, 50.0f, 50.0f));
BoxComponent->SetCollisionProfileName(TEXT("Pawn"));
}
=====
Any thoughts?
Thank you in advance.