├── Move ├── Build │ └── Windows │ │ └── Application.ico ├── Content │ └── Spider │ │ ├── SpiderPawnBP.uasset │ │ └── SpiderMesh │ │ ├── Spider_Idle.uasset │ │ ├── Spider_Mesh.uasset │ │ ├── Spider_Walk.uasset │ │ ├── BlendSpace1DWalkIdle.uasset │ │ ├── Spider_Mesh_Skeleton.uasset │ │ ├── Spider_WalkBackwards.uasset │ │ ├── Spider_Mesh_PhysicsAsset.uasset │ │ └── SpiderSkeleton_AnimBlueprint.uasset ├── Config │ ├── DefaultGame.ini │ ├── DefaultEditor.ini │ ├── DefaultEngine.ini │ └── DefaultInput.ini ├── Source │ ├── Move │ │ ├── Move.h │ │ ├── Move.cpp │ │ ├── MoveGameMode.h │ │ ├── MoveGameMode.cpp │ │ ├── SpiderMovementComponent.h │ │ ├── Move.Build.cs │ │ ├── SpiderMovementComponent.cpp │ │ ├── SpiderPawn.h │ │ ├── Resources │ │ │ └── Windows │ │ │ │ └── Move.rc │ │ └── SpiderPawn.cpp │ ├── Move.Target.cs │ └── MoveEditor.Target.cs └── Move.uproject ├── .gitignore ├── README.md └── License /Move/Build/Windows/Application.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Build/Windows/Application.ico -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderPawnBP.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderPawnBP.uasset -------------------------------------------------------------------------------- /Move/Config/DefaultGame.ini: -------------------------------------------------------------------------------- 1 | [StartupActions] 2 | bAddPacks=True 3 | InsertPack=(PackSource="StarterContent.upack",PackName="StarterContent") 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Move/Content/StarterContent/ 2 | Move/Saved/ 3 | Move/Intermediate/Config/CoalescedSourceConfigs/EditorUserSettings.ini 4 | Move/Intermediate/ 5 | -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_Idle.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_Idle.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_Mesh.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_Mesh.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_Walk.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_Walk.uasset -------------------------------------------------------------------------------- /Move/Source/Move/Move.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "Engine.h" 6 | 7 | -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/BlendSpace1DWalkIdle.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/BlendSpace1DWalkIdle.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_Mesh_Skeleton.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_Mesh_Skeleton.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_WalkBackwards.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_WalkBackwards.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/Spider_Mesh_PhysicsAsset.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/Spider_Mesh_PhysicsAsset.uasset -------------------------------------------------------------------------------- /Move/Content/Spider/SpiderMesh/SpiderSkeleton_AnimBlueprint.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eibonscroll/UE4SpiderAI/HEAD/Move/Content/Spider/SpiderMesh/SpiderSkeleton_AnimBlueprint.uasset -------------------------------------------------------------------------------- /Move/Config/DefaultEditor.ini: -------------------------------------------------------------------------------- 1 | [EditoronlyBP] 2 | bAllowClassAndBlueprintPinMatching=true 3 | bReplaceBlueprintWithClass=true 4 | bDontLoadBlueprintOutsideEditor=true 5 | bBlueprintIsNotBlueprintType=true 6 | -------------------------------------------------------------------------------- /Move/Source/Move/Move.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "Move.h" 4 | 5 | IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, Move, "Move" ); 6 | -------------------------------------------------------------------------------- /Move/Move.uproject: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "EngineAssociation": "4.10", 4 | "Category": "", 5 | "Description": "", 6 | "Modules": [ 7 | { 8 | "Name": "Move", 9 | "Type": "Runtime", 10 | "LoadingPhase": "Default" 11 | } 12 | ], 13 | "Plugins": [ 14 | { 15 | "Name": "Substance", 16 | "Enabled": true 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Move/Source/Move/MoveGameMode.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "GameFramework/GameMode.h" 6 | #include "MoveGameMode.generated.h" 7 | 8 | /** 9 | * 10 | */ 11 | UCLASS() 12 | class MOVE_API AMoveGameMode : public AGameMode 13 | { 14 | GENERATED_BODY() 15 | 16 | virtual void StartPlay() override; 17 | 18 | AMoveGameMode(const FObjectInitializer& ObjectInitializer); 19 | }; 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UE4SpiderAI 2 | UE4 Spider AI 3 | 4 | Source Code to go with blog http://www.mike-purvis.com/?p=223 UE4 How to make Spider AI. 5 | 6 | The source is provided under the MIT open-source license and you can do whatever you want with it. 7 | 8 | The assets are privately held at this point, the artist who made them holds the license. They are very boxy right now. If the project is successful we will look at doing proper models and anmitations to go with this, and submit it to Unreal Tournment. 9 | -------------------------------------------------------------------------------- /Move/Source/Move/MoveGameMode.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "Move.h" 4 | #include "MoveGameMode.h" 5 | 6 | AMoveGameMode::AMoveGameMode(const FObjectInitializer& ObjectInitializer) 7 | : Super(ObjectInitializer) 8 | { 9 | 10 | } 11 | 12 | void AMoveGameMode::StartPlay() 13 | { 14 | Super::StartPlay(); 15 | 16 | StartMatch(); 17 | 18 | if (GEngine) 19 | { 20 | //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Spider")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Move/Source/Move/SpiderMovementComponent.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "GameFramework/PawnMovementComponent.h" 6 | #include "SpiderMovementComponent.generated.h" 7 | 8 | /** 9 | * 10 | */ 11 | UCLASS() 12 | class MOVE_API USpiderMovementComponent : public UPawnMovementComponent 13 | { 14 | GENERATED_BODY() 15 | 16 | public: 17 | virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override; 18 | 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /Move/Source/Move.Target.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class MoveTarget : TargetRules 7 | { 8 | public MoveTarget(TargetInfo Target) 9 | { 10 | Type = TargetType.Game; 11 | } 12 | 13 | // 14 | // TargetRules interface. 15 | // 16 | 17 | public override void SetupBinaries( 18 | TargetInfo Target, 19 | ref List OutBuildBinaryConfigurations, 20 | ref List OutExtraModuleNames 21 | ) 22 | { 23 | OutExtraModuleNames.AddRange( new string[] { "Move" } ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Move/Source/MoveEditor.Target.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class MoveEditorTarget : TargetRules 7 | { 8 | public MoveEditorTarget(TargetInfo Target) 9 | { 10 | Type = TargetType.Editor; 11 | } 12 | 13 | // 14 | // TargetRules interface. 15 | // 16 | 17 | public override void SetupBinaries( 18 | TargetInfo Target, 19 | ref List OutBuildBinaryConfigurations, 20 | ref List OutExtraModuleNames 21 | ) 22 | { 23 | OutExtraModuleNames.AddRange( new string[] { "Move" } ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Move/Source/Move/Move.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class Move : ModuleRules 6 | { 7 | public Move(TargetInfo Target) 8 | { 9 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); 10 | 11 | PrivateDependencyModuleNames.AddRange(new string[] { }); 12 | 13 | // Uncomment if you are using Slate UI 14 | // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); 15 | 16 | // Uncomment if you are using online features 17 | // PrivateDependencyModuleNames.Add("OnlineSubsystem"); 18 | // if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64)) 19 | // { 20 | // if (UEBuildConfiguration.bCompileSteamOSS == true) 21 | // { 22 | // DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam"); 23 | // } 24 | // } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Michael Purvis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Move/Source/Move/SpiderMovementComponent.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "Move.h" 4 | #include "SpiderMovementComponent.h" 5 | 6 | void USpiderMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) 7 | { 8 | Super::TickComponent(DeltaTime, TickType, ThisTickFunction); 9 | 10 | // Make sure that everything is still valid, and that we are allowed to move. 11 | if (!PawnOwner || !UpdatedComponent || ShouldSkipUpdate(DeltaTime)) 12 | { 13 | return; 14 | } 15 | 16 | // Get (and then clear) the movement vector that we set in ACollidingPawn::Tick 17 | FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(1.0f) * DeltaTime * 150.0f; 18 | if (!DesiredMovementThisFrame.IsNearlyZero()) 19 | { 20 | FHitResult Hit; 21 | SafeMoveUpdatedComponent(DesiredMovementThisFrame, UpdatedComponent->GetComponentRotation(), true, Hit); 22 | 23 | // If we bumped into something, try to slide along it 24 | if (Hit.IsValidBlockingHit()) 25 | { 26 | SlideAlongSurface(DesiredMovementThisFrame, 1.f - Hit.Time, Hit.Normal, Hit); 27 | } 28 | } 29 | }; 30 | 31 | 32 | -------------------------------------------------------------------------------- /Move/Config/DefaultEngine.ini: -------------------------------------------------------------------------------- 1 | [URL] 2 | [/Script/EngineSettings.GameMapsSettings] 3 | EditorStartupMap=/Game/StarterContent/Maps/Minimal_Default 4 | GameDefaultMap=/Game/StarterContent/Maps/Minimal_Default 5 | GlobalDefaultGameMode="/Script/Move.MoveGameMode" 6 | 7 | [/Script/Engine.UserInterfaceSettings] 8 | RenderFocusRule=NavigationOnly 9 | DefaultCursor=None 10 | TextEditBeamCursor=None 11 | CrosshairsCursor=None 12 | GrabHandCursor=None 13 | GrabHandClosedCursor=None 14 | SlashedCircleCursor=None 15 | UIScaleRule=ShortestSide 16 | UIScaleCurve=(EditorCurveData=(Keys=((Time=480.000000,Value=0.444000),(Time=720.000000,Value=0.666000),(Time=1080.000000,Value=1.000000),(Time=8640.000000,Value=8.000000))),ExternalCurve=None) 17 | 18 | [/Script/Engine.RendererSettings] 19 | r.MobileHDR=True 20 | r.AllowOcclusionQueries=True 21 | r.MinScreenRadiusForLights=0.030000 22 | r.MinScreenRadiusForDepthPrepass=0.030000 23 | r.PrecomputedVisibilityWarning=False 24 | r.TextureStreaming=True 25 | Compat.UseDXT5NormalMaps=False 26 | r.AllowStaticLighting=True 27 | r.NormalMapsForStaticLighting=False 28 | r.GBuffer=True 29 | r.GenerateMeshDistanceFields=False 30 | r.Shadow.DistanceFieldPenumbraSize=0.050000 31 | r.TessellationAdaptivePixelsPerTriangle=48.000000 32 | r.SeparateTranslucency=True 33 | r.TranslucentSortPolicy=0 34 | TranslucentSortAxis=(X=0.000000,Y=-1.000000,Z=0.000000) 35 | r.CustomDepth=1 36 | r.DefaultFeature.Bloom=True 37 | r.DefaultFeature.AmbientOcclusion=True 38 | r.DefaultFeature.AmbientOcclusionStaticFraction=True 39 | r.DefaultFeature.AutoExposure=True 40 | r.DefaultFeature.MotionBlur=True 41 | r.DefaultFeature.LensFlare=True 42 | r.DefaultFeature.AntiAliasing=2 43 | r.EarlyZPass=3 44 | r.EarlyZPassMovable=False 45 | r.DBuffer=False 46 | r.ClearSceneMethod=1 47 | r.WireframeCullThreshold=5.000000 48 | UIScaleRule=ShortestSide 49 | UIScaleCurve=(EditorCurveData=(Keys=),ExternalCurve=None) 50 | 51 | [/Script/HardwareTargeting.HardwareTargetingSettings] 52 | TargetedHardwareClass=Desktop 53 | AppliedTargetedHardwareClass=Desktop 54 | DefaultGraphicsPerformance=Maximum 55 | AppliedDefaultGraphicsPerformance=Maximum 56 | 57 | 58 | -------------------------------------------------------------------------------- /Move/Source/Move/SpiderPawn.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "GameFramework/Pawn.h" 6 | #include "SpiderMovementComponent.h" 7 | #include "SpiderPawn.generated.h" 8 | 9 | UCLASS() 10 | class MOVE_API ASpiderPawn : public APawn 11 | { 12 | GENERATED_BODY() 13 | 14 | private: 15 | USkeletalMeshComponent * GetMesh(); 16 | 17 | bool TransitionToWall(bool IsConvex); 18 | 19 | FVector LastSurfaceNormal; 20 | 21 | FVector GetZVector(); 22 | 23 | FVector DirectionSocketLocation; 24 | 25 | FVector UnderBellySocketLoc; 26 | FVector FrontSocketLoc; 27 | FVector BellySocketLoc; 28 | FVector FLSocketLoc; 29 | FVector FRSocketLoc; 30 | FVector BLSocketLoc; 31 | FVector BRSocketLoc; 32 | FVector ConvexCheckLoc; 33 | 34 | void StickToSurface(); 35 | 36 | public: 37 | // Sets default values for this pawn's properties 38 | ASpiderPawn(); 39 | 40 | // Called when the game starts or when spawned 41 | virtual void BeginPlay() override; 42 | 43 | // Called every frame 44 | virtual void Tick( float DeltaSeconds ) override; 45 | 46 | // Called to bind functionality to input 47 | virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override; 48 | 49 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spider Move") 50 | float speed; 51 | 52 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spider Move") 53 | float rotationSpeed; 54 | 55 | UFUNCTION(BlueprintCallable, Category = "Spider Move") 56 | void StopMovement(); 57 | 58 | UFUNCTION(BlueprintCallable, Category = "Spider Move") 59 | void MoveForward(); 60 | 61 | UFUNCTION(BlueprintCallable, Category = "Spider Move") 62 | void MoveBackward(); 63 | 64 | UFUNCTION(BlueprintCallable, Category = "Spider Move") 65 | void RotateRight(); 66 | 67 | UFUNCTION(BlueprintCallable, Category = "Spider Move") 68 | void RotateLeft(); 69 | 70 | class USpiderMovementComponent* MovementComponent; 71 | 72 | virtual UPawnMovementComponent* GetMovementComponent() const override; 73 | }; 74 | -------------------------------------------------------------------------------- /Move/Config/DefaultInput.ini: -------------------------------------------------------------------------------- 1 | 2 | [/Script/Engine.InputSettings] 3 | -AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 4 | -AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 5 | -AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 6 | -AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) 7 | -AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) 8 | -AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) 9 | +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 10 | +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 11 | +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 12 | +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) 13 | +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) 14 | +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) 15 | bUseMouseForTouch=False 16 | bEnableMouseSmoothing=True 17 | bEnableFOVScaling=True 18 | FOVScale=0.011110 19 | DoubleClickTime=0.200000 20 | +ActionMappings=(ActionName="MoveForward",Key=Y,bShift=False,bCtrl=False,bAlt=False,bCmd=False) 21 | +ActionMappings=(ActionName="MoveBackward",Key=H,bShift=False,bCtrl=False,bAlt=False,bCmd=False) 22 | +ActionMappings=(ActionName="RotateRight",Key=J,bShift=False,bCtrl=False,bAlt=False,bCmd=False) 23 | +ActionMappings=(ActionName="RotateLeft",Key=G,bShift=False,bCtrl=False,bAlt=False,bCmd=False) 24 | bAlwaysShowTouchInterface=False 25 | bShowConsoleOnFourFingerTap=True 26 | DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks 27 | ConsoleKey=None 28 | -ConsoleKeys=Tilde 29 | +ConsoleKeys=Tilde 30 | 31 | 32 | -------------------------------------------------------------------------------- /Move/Source/Move/Resources/Windows/Move.rc: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. 2 | 3 | #define APSTUDIO_READONLY_SYMBOLS 4 | ///////////////////////////////////////////////////////////////////////////// 5 | // 6 | // Generated from the TEXTINCLUDE 2 resource. 7 | // 8 | #include 9 | #include "Runtime/Launch/Resources/Version.h" 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | #undef APSTUDIO_READONLY_SYMBOLS 13 | 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Version 27 | // 28 | 29 | VS_VERSION_INFO VERSIONINFO 30 | FILEVERSION ENGINE_MAJOR_VERSION,ENGINE_MINOR_VERSION,ENGINE_PATCH_VERSION,0 31 | PRODUCTVERSION ENGINE_MAJOR_VERSION,ENGINE_MINOR_VERSION,ENGINE_PATCH_VERSION,0 32 | FILEFLAGSMASK 0x17L 33 | #ifdef _DEBUG 34 | FILEFLAGS 0x1L 35 | #else 36 | FILEFLAGS 0x0L 37 | #endif 38 | FILEOS 0x4L 39 | FILETYPE 0x2L 40 | FILESUBTYPE 0x0L 41 | BEGIN 42 | BLOCK "StringFileInfo" 43 | BEGIN 44 | BLOCK "040904b0" 45 | BEGIN 46 | VALUE "CompanyName", EPIC_COMPANY_NAME 47 | VALUE "LegalCopyright", EPIC_COPYRIGHT_STRING 48 | VALUE "ProductName", EPIC_PRODUCT_NAME 49 | VALUE "ProductVersion", ENGINE_VERSION_STRING 50 | VALUE "FileDescription", "Move" 51 | VALUE "InternalName", "Move" 52 | VALUE "OriginalFilename", "Move.exe" 53 | END 54 | END 55 | BLOCK "VarFileInfo" 56 | BEGIN 57 | VALUE "Translation", 0x409, 1200 58 | END 59 | END 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // 63 | // Icon 64 | // 65 | 66 | // Icon with lowest ID value placed first to ensure application icon 67 | // remains consistent on all systems. 68 | IDICON_UE4Game ICON "../../../../Build/Windows/Application.ico" 69 | 70 | #endif // English (U.S.) resources 71 | ///////////////////////////////////////////////////////////////////////////// 72 | 73 | 74 | 75 | //#ifndef APSTUDIO_INVOKED 76 | ///////////////////////////////////////////////////////////////////////////// 77 | // 78 | // Generated from the TEXTINCLUDE 3 resource. 79 | // 80 | 81 | 82 | ///////////////////////////////////////////////////////////////////////////// 83 | //#endif // not APSTUDIO_INVOKED 84 | -------------------------------------------------------------------------------- /Move/Source/Move/SpiderPawn.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "Move.h" 4 | #include "SpiderPawn.h" 5 | 6 | 7 | // Sets default values 8 | ASpiderPawn::ASpiderPawn() 9 | { 10 | LastSurfaceNormal = FVector(0,0,1); 11 | 12 | // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. 13 | PrimaryActorTick.bCanEverTick = true; 14 | 15 | bUseControllerRotationRoll = false; 16 | bUseControllerRotationPitch = false; 17 | bUseControllerRotationYaw = false; 18 | 19 | // Create an instance of our movement component, and tell it to update the root. 20 | MovementComponent = CreateDefaultSubobject(TEXT("CustomMovementComponent")); 21 | MovementComponent->UpdatedComponent = RootComponent; 22 | } 23 | 24 | // Called when the game starts or when spawned 25 | void ASpiderPawn::BeginPlay() 26 | { 27 | Super::BeginPlay(); 28 | 29 | } 30 | 31 | UPawnMovementComponent* ASpiderPawn::GetMovementComponent() const 32 | { 33 | return MovementComponent; 34 | } 35 | 36 | USkeletalMeshComponent* ASpiderPawn::GetMesh() 37 | { 38 | TArray comps; 39 | USkeletalMeshComponent* thisComp = nullptr; 40 | 41 | GetComponents(comps); 42 | for (int i = 0; i < comps.Num(); ++i) 43 | { 44 | thisComp = Cast(comps[i]); 45 | if (thisComp && thisComp->GetName() == "Mesh") 46 | break; 47 | } 48 | return thisComp; 49 | } 50 | 51 | // Called every frame 52 | void ASpiderPawn::Tick( float DeltaTime ) 53 | { 54 | Super::Tick( DeltaTime ); 55 | 56 | bool DidTransition = false; 57 | //Do Spider Traces 58 | DirectionSocketLocation = GetMesh()->GetSocketLocation("DetectionSocket"); 59 | 60 | UnderBellySocketLoc = GetMesh()->GetSocketLocation("UnderBelly"); 61 | FrontSocketLoc = GetMesh()->GetSocketLocation("Front"); 62 | BellySocketLoc = GetMesh()->GetSocketLocation("Belly"); 63 | FLSocketLoc = GetMesh()->GetSocketLocation("FL"); 64 | FRSocketLoc = GetMesh()->GetSocketLocation("FR"); 65 | BLSocketLoc = GetMesh()->GetSocketLocation("BL"); 66 | BRSocketLoc = GetMesh()->GetSocketLocation("BR"); 67 | ConvexCheckLoc = GetMesh()->GetSocketLocation("ConvexCheck"); 68 | 69 | FVector ChararacterForwardVector = GetActorForwardVector(); 70 | FVector ChararacterLocation = GetActorLocation(); 71 | 72 | //temp, up vector will only be up while on ground 73 | ChararacterLocation.Z = ChararacterLocation.Z - 84; 74 | 75 | //location in the ground and infront of spider 76 | FVector PointInFront = ChararacterLocation + (ChararacterForwardVector * 30.0); 77 | 78 | 79 | //The trace data is stored here 80 | FHitResult HitData(ForceInit); 81 | FHitResult HitData2(ForceInit); 82 | 83 | static FName SpiderTraceIdent = FName(TEXT("SpidferTrace")); 84 | FCollisionQueryParams TraceParams(SpiderTraceIdent, true, this); 85 | TraceParams.bTraceAsyncScene = true; 86 | 87 | const FName TraceTag("SpiderTraceTag"); 88 | 89 | GetWorld()->DebugDrawTraceTag = TraceTag; 90 | TraceParams.TraceTag = TraceTag; 91 | FVector HitNormal, HitNormal2; 92 | 93 | //Check if convex corner 94 | if (!GetWorld()->LineTraceSingle(HitData, DirectionSocketLocation, FLSocketLoc, ECollisionChannel::ECC_Pawn, TraceParams) && 95 | !GetWorld()->LineTraceSingle(HitData2, DirectionSocketLocation, FRSocketLoc, ECollisionChannel::ECC_Pawn, TraceParams)) 96 | { 97 | HitNormal = HitData.ImpactNormal; 98 | HitNormal2 = HitData2.ImpactNormal; 99 | 100 | if (!HitData.GetActor() && !HitData2.GetActor()) 101 | { 102 | DidTransition = TransitionToWall(true); 103 | } 104 | } 105 | //Point directly in front 106 | else if (GetWorld()->LineTraceSingle(HitData, BellySocketLoc, FrontSocketLoc, ECollisionChannel::ECC_Pawn, TraceParams)) 107 | { 108 | HitNormal = HitData.ImpactNormal; 109 | if (HitData.GetActor()) 110 | { 111 | DidTransition = TransitionToWall(false); 112 | } 113 | } 114 | 115 | if (!DidTransition) 116 | { 117 | StickToSurface(); 118 | } 119 | } 120 | 121 | // Called to bind functionality to input 122 | void ASpiderPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent) 123 | { 124 | Super::SetupPlayerInputComponent(InputComponent); 125 | 126 | } 127 | 128 | FVector ASpiderPawn::GetZVector() 129 | { 130 | FVector DirectionSocketLocation = GetMesh()->GetSocketLocation("DetectionSocket"); 131 | FVector BellySocketLoc = GetMesh()->GetSocketLocation("Belly"); 132 | return DirectionSocketLocation - BellySocketLoc; 133 | 134 | } 135 | 136 | void ASpiderPawn::StickToSurface() 137 | { 138 | //Grab a ref to the world here 139 | UWorld* world = GetWorld(); 140 | 141 | FHitResult hitResultTrace; 142 | FCollisionQueryParams queryParams; 143 | FCollisionObjectQueryParams objQueryParams; 144 | 145 | queryParams.AddIgnoredActor(this); 146 | 147 | FVector under; 148 | 149 | FVector newUp; 150 | FVector newForward; 151 | FVector newRight; 152 | 153 | //Trace to get the floor normal under your actor 154 | if (world->LineTraceSingle(hitResultTrace, BellySocketLoc, UnderBellySocketLoc, queryParams, objQueryParams)) 155 | { 156 | under = hitResultTrace.ImpactPoint; 157 | newUp = hitResultTrace.ImpactNormal; 158 | } 159 | 160 | //Some math to get the new Axis 161 | FVector currentRightVect = GetActorRightVector(); 162 | newForward = FVector::CrossProduct(currentRightVect, newUp); 163 | newRight = FVector::CrossProduct(newUp, newForward); 164 | 165 | //Build the new transform! 166 | FTransform newTransform(newForward, newRight, newUp, under); 167 | SetActorTransform(newTransform); 168 | } 169 | 170 | bool ASpiderPawn::TransitionToWall(bool IsConvex) 171 | { 172 | bool retval = false; 173 | 174 | //Grab a ref to the world here 175 | UWorld* world = GetWorld(); 176 | 177 | FHitResult hitResultTrace; 178 | FCollisionQueryParams queryParams; 179 | FCollisionObjectQueryParams objQueryParams; 180 | 181 | queryParams.AddIgnoredActor(this); 182 | 183 | FVector Start, End; 184 | 185 | FVector under; 186 | 187 | FVector newUp; 188 | FVector newForward; 189 | FVector newRight; 190 | 191 | if (!IsConvex) 192 | { 193 | Start = BellySocketLoc; 194 | End = FrontSocketLoc; 195 | } 196 | else 197 | { 198 | Start = FrontSocketLoc; 199 | End = ConvexCheckLoc; 200 | } 201 | 202 | //Trace to get the surface normal in front of actor 203 | if (world->LineTraceSingle(hitResultTrace, Start, End, queryParams, objQueryParams)) 204 | { 205 | under = hitResultTrace.ImpactPoint; 206 | newUp = hitResultTrace.ImpactNormal; 207 | 208 | //Some math to get the new Axis 209 | FVector currentRightVect = GetActorRightVector(); 210 | newForward = FVector::CrossProduct(currentRightVect, newUp); 211 | newRight = FVector::CrossProduct(newUp, newForward); 212 | 213 | //Build the new transform! 214 | FTransform newTransform(newForward, newRight, newUp, under); 215 | SetActorTransform(newTransform); 216 | retval = true; 217 | } 218 | 219 | return retval; 220 | } 221 | 222 | void ASpiderPawn::MoveForward() 223 | { 224 | if (MovementComponent && (MovementComponent->UpdatedComponent == RootComponent)) 225 | { 226 | MovementComponent->AddInputVector(GetActorForwardVector() * speed); 227 | } 228 | } 229 | 230 | void ASpiderPawn::StopMovement() 231 | { 232 | if (MovementComponent && (MovementComponent->UpdatedComponent == RootComponent)) 233 | { 234 | MovementComponent->StopMovementImmediately(); 235 | } 236 | } 237 | 238 | void ASpiderPawn::MoveBackward() 239 | { 240 | if (MovementComponent && (MovementComponent->UpdatedComponent == RootComponent)) 241 | { 242 | MovementComponent->AddInputVector(GetActorForwardVector() * -speed); 243 | } 244 | } 245 | 246 | void ASpiderPawn::RotateRight() 247 | { 248 | FTransform TheTransform = this->GetTransform(); 249 | 250 | FRotator rot = FRotator(0, rotationSpeed, 0); 251 | 252 | TheTransform.ConcatenateRotation(rot.Quaternion()); 253 | TheTransform.NormalizeRotation(); 254 | this->SetActorTransform(TheTransform); 255 | } 256 | 257 | void ASpiderPawn::RotateLeft() 258 | { 259 | FTransform TheTransform = this->GetTransform(); 260 | 261 | FRotator rot = FRotator(0, -rotationSpeed, 0); 262 | 263 | TheTransform.ConcatenateRotation(rot.Quaternion()); 264 | TheTransform.NormalizeRotation(); 265 | this->SetActorTransform(TheTransform); 266 | } 267 | --------------------------------------------------------------------------------