Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Obstacles and Interactions #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Config/DefaultInput.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ DoubleClickTime=0.200000
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar)
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Bottom)
+ActionMappings=(ActionName="GrabThrow",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton)
+ActionMappings=(ActionName="Unclimb",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=W)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=-1.000000,Key=S)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY)
Expand Down
3 changes: 3 additions & 0 deletions Content/BP/BP_Obstacles/BP_StepStone.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/LevelPrototyping/Materials/M_CollapseStone.uasset
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown

This file was deleted.

61 changes: 61 additions & 0 deletions Source/NetForms/CharacterPhysicsHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "CharacterPhysicsHandler.h"

// Sets default values for this component's properties
UCharacterPhysicsHandler::UCharacterPhysicsHandler()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;

// ...
}


// Called when the game starts
void UCharacterPhysicsHandler::BeginPlay()
{
Super::BeginPlay();

// ...

MyOwner = GetOwner();
}


// Called every frame
void UCharacterPhysicsHandler::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

// ...
if(NoOfForceApplied)
{
ApplyForce(DeltaTime);
}
}

void UCharacterPhysicsHandler::AddForce(FVector ForceDir, float ForceMag)
{
Force += ForceDir * ForceMag;
NoOfForceApplied++;
}

void UCharacterPhysicsHandler::ApplyForce(float DeltaTime)
{
if (MyOwner != nullptr)
{
FVector pos = MyOwner->GetActorLocation();
pos += Force * DeltaTime;
MyOwner->SetActorLocation(pos);
}
}

void UCharacterPhysicsHandler::RemoveForce(FVector ForceDir, float ForceMag)
{
Force -= ForceDir * ForceMag;
NoOfForceApplied--;
}

36 changes: 36 additions & 0 deletions Source/NetForms/CharacterPhysicsHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "CharacterPhysicsHandler.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class NETFORMS_API UCharacterPhysicsHandler : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component's properties
UCharacterPhysicsHandler();

protected:
// Called when the game starts
virtual void BeginPlay() override;

AActor* MyOwner;

public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

void AddForce(FVector ForceDir, float ForceMag);
void ApplyForce(float DeltaTime);
void RemoveForce(FVector ForceDir, float ForceMag);

int NoOfForceApplied = 0;

FVector Force = FVector(0, 0, 0);
};
4 changes: 4 additions & 0 deletions Source/NetForms/NetFormsCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ ANetFormsCharacter::ANetFormsCharacter()
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

// Create the physics controller
PhysicsController = CreateDefaultSubobject<UCharacterPhysicsHandler>(TEXT("PhysicsController"));
this->AddOwnedComponent(PhysicsController);

// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
}
Expand Down
5 changes: 5 additions & 0 deletions Source/NetForms/NetFormsCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "CharacterPhysicsHandler.h"
#include "NetFormsCharacter.generated.h"

UCLASS(config=Game)
Expand All @@ -19,6 +20,10 @@ class ANetFormsCharacter : public ACharacter
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;

/** Physics Controller */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCharacterPhysicsHandler* PhysicsController;

public:
ANetFormsCharacter();

Expand Down
78 changes: 78 additions & 0 deletions Source/NetForms/Obstacles/CollapseStone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "CollapseStone.h"
#include "GameFramework/Character.h"

// Sets default values
ACollapseStone::ACollapseStone()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

TBox->OnComponentBeginOverlap.AddDynamic(this, &ACollapseStone::TriggerEnter);
TBox->OnComponentEndOverlap.AddDynamic(this, &ACollapseStone::TriggerExit);
}

// Called when the game starts or when spawned
void ACollapseStone::BeginPlay()
{
Super::BeginPlay();

TimeTillNextCollapse = TimeBetweenCollapse;
MyMesh = SM_Obstacle->GetStaticMesh();

DynamicMaterial = UMaterialInstanceDynamic::Create(Material, NULL);
MyMesh->SetMaterial(0, DynamicMaterial);
}

// Called every frame
void ACollapseStone::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

if (!IsCollapsed)
{
if (IsPlayerOnPlatform)
{
TimeTillNextCollapse -= DeltaTime;
}
/*else
{
TimeTillNextCollapse += DeltaTime;
}*/
if (TimeTillNextCollapse < 0)
{
IsCollapsed = true;
TimeTillNextCollapse = TimeBetweenCollapse;
SM_Obstacle->SetStaticMesh(nullptr);
}
}
else
{
TimeTillNextCollapse -= DeltaTime;
if (TimeTillNextCollapse < 0)
{
IsCollapsed = false;
TimeTillNextCollapse = TimeBetweenCollapse;
SM_Obstacle->SetStaticMesh(MyMesh);
}
}
float blend = TimeTillNextCollapse/ TimeBetweenCollapse;
//GEngine->AddOnScreenDebugMessage(-1, -1, FColor::Blue, FString::Printf(TEXT("lol, %f"), blend));
DynamicMaterial->SetScalarParameterValue(TEXT("Blend"), blend);
}

void ACollapseStone::TriggerEnter(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Super::TriggerEnter(HitComponent, OtherActor, OtherComp, otherBodyIndex, bFromSweep, SweepResult);
UE_LOG(LogTemp, Warning, TEXT("Stone"));
IsPlayerOnPlatform = true;
}

void ACollapseStone::TriggerExit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex)
{
Super::TriggerExit(HitComponent, OtherActor, OtherComp, otherBodyIndex);
IsPlayerOnPlatform = false;
}

41 changes: 41 additions & 0 deletions Source/NetForms/Obstacles/CollapseStone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "ObstacleBase.h"
#include "CollapseStone.generated.h"

UCLASS()
class NETFORMS_API ACollapseStone : public AObstacleBase
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
ACollapseStone();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

virtual void TriggerEnter(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
virtual void TriggerExit(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex) override;

bool IsCollapsed = false;
bool IsPlayerOnPlatform = false;

float TimeBetweenCollapse = 4;

float TimeTillNextCollapse;

UStaticMesh* MyMesh;
UMaterialInstanceDynamic* DynamicMaterial;

UPROPERTY(EditAnywhere)
UMaterialInterface* Material;
};
11 changes: 8 additions & 3 deletions Source/NetForms/Obstacles/ObstacleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AObstacleBase::AObstacleBase()
PrimaryActorTick.bCanEverTick = true;

SM_Obstacle = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ObstacleMesh"));
RootComponent = SM_Obstacle;
SetRootComponent(SM_Obstacle);

TBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TBOX"));
TBox->SetGenerateOverlapEvents(true);
Expand All @@ -37,7 +37,12 @@ void AObstacleBase::Tick(float DeltaTime)

}

void AObstacleBase::TriggerEnter(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
void AObstacleBase::TriggerEnter(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{

}
}

void AObstacleBase::TriggerExit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex)
{

}
3 changes: 2 additions & 1 deletion Source/NetForms/Obstacles/ObstacleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ class NETFORMS_API AObstacleBase : public AActor

UFUNCTION()
virtual void TriggerEnter(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

UFUNCTION()
virtual void TriggerExit(class UPrimitiveComponent* HitComponent, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 otherBodyIndex);
};
38 changes: 38 additions & 0 deletions Source/NetForms/Obstacles/ObstacleSpawner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "ObstacleSpawner.h"
#include "ObstacleBase.h"

// Sets default values
AObstacleSpawner::AObstacleSpawner()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
SetRootComponent(SceneComponent);
}

// Called when the game starts or when spawned
void AObstacleSpawner::BeginPlay()
{
Super::BeginPlay();

TimeTillNextSpawn = TimeBetweenSpawn;
}

// Called every frame
void AObstacleSpawner::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

TimeTillNextSpawn -= DeltaTime;

if (TimeTillNextSpawn < 0)
{
GetWorld()->SpawnActor<AObstacleBase>(BP_Obstacle,GetActorLocation(),GetActorRotation());
TimeTillNextSpawn = TimeBetweenSpawn;
}
}

Loading