diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index fd9e6fa..b4e16b3 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -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) diff --git a/Content/BP/BP_Obstacles/BP_StepStone.uasset b/Content/BP/BP_Obstacles/BP_StepStone.uasset new file mode 100644 index 0000000..e4898c1 --- /dev/null +++ b/Content/BP/BP_Obstacles/BP_StepStone.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a58b995d2dcf6e92d2c2f132e14dd9cf75b36d3ed85bf59cd68cf4ca400e5c0 +size 34272 diff --git a/Content/LevelPrototyping/Materials/M_CollapseStone.uasset b/Content/LevelPrototyping/Materials/M_CollapseStone.uasset new file mode 100644 index 0000000..3c7532f --- /dev/null +++ b/Content/LevelPrototyping/Materials/M_CollapseStone.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c126d70963dad7e44c76a8ec047258e015628bd4f352657b862e30517a402889 +size 10424 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/1/M0/20DKZ7QN2JXRYUWDBRZSSH.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/1/M0/20DKZ7QN2JXRYUWDBRZSSH.uasset new file mode 100644 index 0000000..e3af73a --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/1/M0/20DKZ7QN2JXRYUWDBRZSSH.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8285193dd7d3ceb5cf151467c7caf00f6d2b8ba9a3b6602f34160573d70d132 +size 3467 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/2/1S/RM9GPKGOK99CPVAV652FNE.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/2/1S/RM9GPKGOK99CPVAV652FNE.uasset new file mode 100644 index 0000000..0f78a69 --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/2/1S/RM9GPKGOK99CPVAV652FNE.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0ab7c4ee88c56ad03cf4757db4db7acd07be5d06b5b5759488ba3290b19c972 +size 4291 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/4/MA/YTJ3RMDA2Q15C9LAQ4MJ90.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/4/MA/YTJ3RMDA2Q15C9LAQ4MJ90.uasset new file mode 100644 index 0000000..f62faaa --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/4/MA/YTJ3RMDA2Q15C9LAQ4MJ90.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e80353133a5a10865a74699fe295c17e61d4a4ac4474c48a0d03f8eb747f467 +size 4408 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/IZ/ZYR512WUTWJB5W62OYONER.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/IZ/ZYR512WUTWJB5W62OYONER.uasset new file mode 100644 index 0000000..352eab9 --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/IZ/ZYR512WUTWJB5W62OYONER.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2523a24c285b7bd96b999e3be742df1364931547553933752a318aa620169d7 +size 3642 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/UZ/5XA8D77AW0G2FN36PMFOTZ.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/UZ/5XA8D77AW0G2FN36PMFOTZ.uasset new file mode 100644 index 0000000..f1bea34 --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/7/UZ/5XA8D77AW0G2FN36PMFOTZ.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92e4c7172519a5a9a45ccc145aeb09bb29c35ac9a7305a228f6bc89ad5e3c2dd +size 3733 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/B/GU/XV8CD6HZA82KCRTRRMS4YT.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/B/GU/XV8CD6HZA82KCRTRRMS4YT.uasset new file mode 100644 index 0000000..c3bf9a5 --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/B/GU/XV8CD6HZA82KCRTRRMS4YT.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1ad59c7366f97b1472f8ec902e3c91d8d927d2483fa1ebb99b98c9749c64d84 +size 3082 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/D/DE/SWSI13675DVYIZ0N4NF7Y3.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/D/DE/SWSI13675DVYIZ0N4NF7Y3.uasset index 3ce56de..de86d40 100644 --- a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/D/DE/SWSI13675DVYIZ0N4NF7Y3.uasset +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/D/DE/SWSI13675DVYIZ0N4NF7Y3.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:352b69431956fc638963212a825fb851b2c2cd2a960d0dffd85678962f319613 +oid sha256:ebeafea920d2552ca74b920b4f05cfe739fd3520356d0d1ebca523e005c59931 size 4178 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/FC/50RLXMO5Y6NXSD2KZXCXNF.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/FC/50RLXMO5Y6NXSD2KZXCXNF.uasset deleted file mode 100644 index 3c63fb2..0000000 --- a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/FC/50RLXMO5Y6NXSD2KZXCXNF.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:62ecb937b5442568f7464abbdf68bc013301acd511ae5fc9baa3d6b48259611e -size 3790 diff --git a/Source/NetForms/CharacterPhysicsHandler.cpp b/Source/NetForms/CharacterPhysicsHandler.cpp new file mode 100644 index 0000000..fbe50c0 --- /dev/null +++ b/Source/NetForms/CharacterPhysicsHandler.cpp @@ -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--; +} + diff --git a/Source/NetForms/CharacterPhysicsHandler.h b/Source/NetForms/CharacterPhysicsHandler.h new file mode 100644 index 0000000..94789db --- /dev/null +++ b/Source/NetForms/CharacterPhysicsHandler.h @@ -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); +}; diff --git a/Source/NetForms/NetFormsCharacter.cpp b/Source/NetForms/NetFormsCharacter.cpp index 93f94ea..e6381f6 100644 --- a/Source/NetForms/NetFormsCharacter.cpp +++ b/Source/NetForms/NetFormsCharacter.cpp @@ -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(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++) } diff --git a/Source/NetForms/NetFormsCharacter.h b/Source/NetForms/NetFormsCharacter.h index 5f35bb2..6f95a91 100644 --- a/Source/NetForms/NetFormsCharacter.h +++ b/Source/NetForms/NetFormsCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "GameFramework/Character.h" +#include "CharacterPhysicsHandler.h" #include "NetFormsCharacter.generated.h" UCLASS(config=Game) @@ -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(); diff --git a/Source/NetForms/Obstacles/CollapseStone.cpp b/Source/NetForms/Obstacles/CollapseStone.cpp new file mode 100644 index 0000000..62826ba --- /dev/null +++ b/Source/NetForms/Obstacles/CollapseStone.cpp @@ -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; +} + diff --git a/Source/NetForms/Obstacles/CollapseStone.h b/Source/NetForms/Obstacles/CollapseStone.h new file mode 100644 index 0000000..b59240e --- /dev/null +++ b/Source/NetForms/Obstacles/CollapseStone.h @@ -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; +}; diff --git a/Source/NetForms/Obstacles/ObstacleBase.cpp b/Source/NetForms/Obstacles/ObstacleBase.cpp index 8724145..c66cdc1 100644 --- a/Source/NetForms/Obstacles/ObstacleBase.cpp +++ b/Source/NetForms/Obstacles/ObstacleBase.cpp @@ -10,7 +10,7 @@ AObstacleBase::AObstacleBase() PrimaryActorTick.bCanEverTick = true; SM_Obstacle = CreateDefaultSubobject(TEXT("ObstacleMesh")); - RootComponent = SM_Obstacle; + SetRootComponent(SM_Obstacle); TBox = CreateDefaultSubobject(TEXT("TBOX")); TBox->SetGenerateOverlapEvents(true); @@ -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) { -} \ No newline at end of file +} + +void AObstacleBase::TriggerExit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex) +{ + +} diff --git a/Source/NetForms/Obstacles/ObstacleBase.h b/Source/NetForms/Obstacles/ObstacleBase.h index 65eb63b..ba2d842 100644 --- a/Source/NetForms/Obstacles/ObstacleBase.h +++ b/Source/NetForms/Obstacles/ObstacleBase.h @@ -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); }; diff --git a/Source/NetForms/Obstacles/ObstacleSpawner.cpp b/Source/NetForms/Obstacles/ObstacleSpawner.cpp new file mode 100644 index 0000000..e1c35c4 --- /dev/null +++ b/Source/NetForms/Obstacles/ObstacleSpawner.cpp @@ -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(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(BP_Obstacle,GetActorLocation(),GetActorRotation()); + TimeTillNextSpawn = TimeBetweenSpawn; + } +} + diff --git a/Source/NetForms/Obstacles/ObstacleSpawner.h b/Source/NetForms/Obstacles/ObstacleSpawner.h new file mode 100644 index 0000000..66a4318 --- /dev/null +++ b/Source/NetForms/Obstacles/ObstacleSpawner.h @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "ObstacleBase.h" +#include "ObstacleSpawner.generated.h" + +UCLASS() +class NETFORMS_API AObstacleSpawner : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AObstacleSpawner(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + class USceneComponent* SceneComponent; + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + + UPROPERTY(EditAnywhere) + TSubclassOf BP_Obstacle; + + float TimeBetweenSpawn = 4; + float TimeTillNextSpawn; +}; diff --git a/Source/NetForms/Obstacles/Punch.cpp b/Source/NetForms/Obstacles/Punch.cpp index 036ab81..db72264 100644 --- a/Source/NetForms/Obstacles/Punch.cpp +++ b/Source/NetForms/Obstacles/Punch.cpp @@ -74,6 +74,8 @@ void APunch::TriggerEnter(class UPrimitiveComponent* HitComponent, class AActor* { Super::TriggerEnter(HitComponent, OtherActor, OtherComp, otherBodyIndex, bFromSweep, SweepResult); + UE_LOG(LogTemp, Warning, TEXT("Punch")); + ACharacter* OtherCharacter = Cast(OtherActor); if (OtherCharacter != nullptr) { diff --git a/Source/NetForms/Obstacles/Spaceship.cpp b/Source/NetForms/Obstacles/Spaceship.cpp new file mode 100644 index 0000000..7b660dc --- /dev/null +++ b/Source/NetForms/Obstacles/Spaceship.cpp @@ -0,0 +1,39 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Spaceship.h" +#include "GameFramework/Character.h" + +// Sets default values +ASpaceship::ASpaceship() +{ + // 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, &ASpaceship::TriggerEnter); + TBox->OnComponentEndOverlap.AddDynamic(this, &ASpaceship::TriggerExit); +} + +// Called when the game starts or when spawned +void ASpaceship::BeginPlay() +{ + Super::BeginPlay(); +} + +void ASpaceship::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + +} + + +void ASpaceship::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); + + OtherCharacter = Cast(OtherActor); + PlayerController = Cast(OtherActor); + + OtherCharacter->DisableInput(PlayerController); +} \ No newline at end of file diff --git a/Source/NetForms/Obstacles/Spaceship.h b/Source/NetForms/Obstacles/Spaceship.h new file mode 100644 index 0000000..f897bae --- /dev/null +++ b/Source/NetForms/Obstacles/Spaceship.h @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "ObstacleBase.h" +#include "Spaceship.generated.h" + +UCLASS() +class NETFORMS_API ASpaceship : public AObstacleBase +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ASpaceship(); + +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; + + ACharacter* OtherCharacter; + APlayerController* PlayerController; +}; diff --git a/Source/NetForms/Obstacles/Spinner.cpp b/Source/NetForms/Obstacles/Spinner.cpp index 6fb645b..7779204 100644 --- a/Source/NetForms/Obstacles/Spinner.cpp +++ b/Source/NetForms/Obstacles/Spinner.cpp @@ -2,12 +2,17 @@ #include "Spinner.h" +#include "GameFramework/Character.h" +#include "./../CharacterPhysicsHandler.h" // Sets default values ASpinner::ASpinner() { // 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, &ASpinner::TriggerEnter); + TBox->OnComponentEndOverlap.AddDynamic(this, &ASpinner::TriggerExit); } // Called when the game starts or when spawned @@ -15,6 +20,7 @@ void ASpinner::BeginPlay() { Super::BeginPlay(); + InitPos = GetActorLocation(); } // Called every frame @@ -22,6 +28,11 @@ void ASpinner::Tick(float DeltaTime) { Super::Tick(DeltaTime); + if (IsOnPlatform) + { + DelTime = DeltaTime; + } + FRotator NewRot = FRotator(PitchValue, YawValue, RollValue); FQuat QuatRot = FQuat(NewRot); @@ -29,3 +40,35 @@ void ASpinner::Tick(float DeltaTime) AddActorLocalRotation(QuatRot, false, 0, ETeleportType::None); } +void ASpinner::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); + + IsOnPlatform = true; + + ACharacter* OtherCharacter = Cast(OtherActor); + /*UCharacterPhysicsHandler* CharacterPhysicsController = Cast(OtherActor);*/ + + if (OtherCharacter != nullptr) + { + float Force = (OtherActor->GetActorLocation() - InitPos).Size(); + ForceDir = (OtherActor->GetActorLocation() - InitPos)/Force; + ForceMag = FMath::Square(YawValue) * Force; + + //CharacterPhysicsController->AddForce(ForceDir, ForceMag); + } +} + +void ASpinner::TriggerExit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex) +{ + Super::TriggerExit(HitComponent, OtherActor, OtherComp, otherBodyIndex); + + UCharacterPhysicsHandler* CharacterPhysicsController = Cast(OtherActor); + + /*if (CharacterPhysicsController != nullptr) + { + CharacterPhysicsController->RemoveForce(ForceDir, ForceMag); + }*/ + + IsOnPlatform = false; +} \ No newline at end of file diff --git a/Source/NetForms/Obstacles/Spinner.h b/Source/NetForms/Obstacles/Spinner.h index f314bb7..740a55d 100644 --- a/Source/NetForms/Obstacles/Spinner.h +++ b/Source/NetForms/Obstacles/Spinner.h @@ -23,6 +23,9 @@ class NETFORMS_API ASpinner : public AObstacleBase // Called every frame virtual void Tick(float DeltaTime) override; + void TriggerEnter(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override; + void TriggerExit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 otherBodyIndex) override; + UPROPERTY(EditAnywhere, Category = Movement) float PitchValue = 0; @@ -31,4 +34,13 @@ class NETFORMS_API ASpinner : public AObstacleBase UPROPERTY(EditAnywhere, Category = Movement) float RollValue = 0; + + UPROPERTY(EditAnywhere, Category = Movement) + float DelTime = 0; + + UPROPERTY(EditAnywhere, Category = Movement) + FVector InitPos; + + UPROPERTY(EditAnywhere, Category = Movement) + bool IsOnPlatform = false; }; diff --git a/Source/NetForms/Obstacles/StepStone.cpp b/Source/NetForms/Obstacles/StepStone.cpp new file mode 100644 index 0000000..7e57cde --- /dev/null +++ b/Source/NetForms/Obstacles/StepStone.cpp @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "StepStone.h" +#include "GameFramework/Character.h" + +// Sets default values +AStepStone::AStepStone() +{ + // 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; + +} + +// Called when the game starts or when spawned +void AStepStone::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AStepStone::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + FVector currLocation = GetActorLocation(); + currLocation += movDir * speed * DeltaTime; + SetActorLocation(currLocation); +} + diff --git a/Source/NetForms/Obstacles/StepStone.h b/Source/NetForms/Obstacles/StepStone.h new file mode 100644 index 0000000..3245295 --- /dev/null +++ b/Source/NetForms/Obstacles/StepStone.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "ObstacleBase.h" +#include "StepStone.generated.h" + +UCLASS() +class NETFORMS_API AStepStone : public AObstacleBase +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AStepStone(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float speed = 0; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FVector movDir = FVector(1, 0, 0); +};