From 270f69572ce6f57c72be105b6fcb4572bc3e9cdb Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Fri, 28 Oct 2022 16:25:57 +0800 Subject: [PATCH 1/5] Replaced cout with SHLOG --- SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp index 551233db..057568d6 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp @@ -29,7 +29,7 @@ namespace SHADE { system.second->Init(); #ifdef _DEBUG - std::cout << system.first << " Init" << std::endl; + SHLOG_INFO("Initialising System {}...", system.first) #endif } } From c9b116b8beef49dfb56409493b3bc9e416d66db9 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 29 Oct 2022 14:51:34 +0800 Subject: [PATCH 2/5] Added skeleton functions to managed GameObject for scene graph interface --- SHADE_Managed/src/Engine/GameObject.cxx | 19 +++++++++++++++++-- SHADE_Managed/src/Engine/GameObject.hxx | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 8c78e399..d425a43a 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited. #include "GameObject.hxx" // External Dependencies #include "ECS_Base/Managers/SHEntityManager.h" +#include "Scene/SHSceneGraph.h" // Project Headers #include "ECS.hxx" #include "Scripts/ScriptStore.hxx" @@ -58,6 +59,14 @@ namespace SHADE { return true; // TODO: Update once we have an equivalent on the Entity object } + GameObject^ GameObject::Parent::get() + { + return nullptr; + } + void GameObject::Parent::set(GameObject^ newParent) + { + + } /*---------------------------------------------------------------------------------*/ /* GameObject Property Functions */ @@ -70,6 +79,10 @@ namespace SHADE { GetNativeEntity().SetActive(active); } + System::Collections::ArrayList^ GameObject::GetChildren() + { + return children; + } /*---------------------------------------------------------------------------------*/ /* Component Functions */ @@ -141,11 +154,13 @@ namespace SHADE /* Constructors */ /*---------------------------------------------------------------------------------*/ GameObject::GameObject(const SHEntity& entity) - : entity { entity.GetEID() } + : entity { entity.GetEID() } + , children{ gcnew System::Collections::ArrayList } {} GameObject::GameObject(Entity entity) - : entity { entity } + : entity { entity } + , children{ gcnew System::Collections::ArrayList } {} /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/GameObject.hxx b/SHADE_Managed/src/Engine/GameObject.hxx index 723d9cec..c4506d55 100644 --- a/SHADE_Managed/src/Engine/GameObject.hxx +++ b/SHADE_Managed/src/Engine/GameObject.hxx @@ -86,6 +86,11 @@ namespace SHADE { bool get(); } + property GameObject^ Parent + { + GameObject^ get(); + void set(GameObject^); + } /*-----------------------------------------------------------------------------*/ /* GameObject Property Functions */ @@ -106,6 +111,16 @@ namespace SHADE /// void SetActive(bool active); + /// + /// Gets the list of GameObjects that are the children of this GameObject. + /// + /// + /// The list of GameObjects that are the children of this GameObject. List is empty is + /// there is none. + /// + System::Collections::ArrayList^ GetChildren(); + + /*-----------------------------------------------------------------------------*/ /* Component Access Functions */ /*-----------------------------------------------------------------------------*/ @@ -235,7 +250,8 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - Entity entity; + Entity entity; + System::Collections::ArrayList^ children; public: /*-----------------------------------------------------------------------------*/ From 72dc07bbd9f5ef716a90fca533862ae3878fb255 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 1 Nov 2022 19:00:31 +0800 Subject: [PATCH 3/5] Shifted Hierarchy interface from Transform to GameObject --- SHADE_Managed/src/Components/Transform.cxx | 26 ---------------------- SHADE_Managed/src/Components/Transform.hxx | 24 -------------------- SHADE_Managed/src/Engine/GameObject.cxx | 21 ++++++++++++----- SHADE_Managed/src/Engine/GameObject.hxx | 12 +++------- 4 files changed, 18 insertions(+), 65 deletions(-) diff --git a/SHADE_Managed/src/Components/Transform.cxx b/SHADE_Managed/src/Components/Transform.cxx index 98f0da4f..927ce87f 100644 --- a/SHADE_Managed/src/Components/Transform.cxx +++ b/SHADE_Managed/src/Components/Transform.cxx @@ -87,15 +87,6 @@ namespace SHADE { GetNativeComponent()->SetWorldScale(Convert::ToNative(val)); } - Transform^ Transform::Parent::get() - { - auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(owner.GetEntity()); - if (!node) - throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity."); - - const auto PARENT = node->GetParent(); - return PARENT ? gcnew Transform(PARENT->GetEntityID()) : nullptr; - } /*---------------------------------------------------------------------------------*/ /* Constructors */ @@ -103,21 +94,4 @@ namespace SHADE Transform::Transform(Entity entity) : Component(entity) {} - - /*---------------------------------------------------------------------------------*/ - /* Usage Functions */ - /*---------------------------------------------------------------------------------*/ - - void Transform::SetParent(Transform^ parent, bool worldPositionStays) - { - auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - auto node = sceneGraph.GetNode(owner.GetEntity()); - if (!node) - throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity."); - - if (parent) - node->SetParent(sceneGraph.GetNode(parent->owner.GetEntity())); - else - sceneGraph.SetParent(parent->owner.GetEntity(), nullptr); - } } diff --git a/SHADE_Managed/src/Components/Transform.hxx b/SHADE_Managed/src/Components/Transform.hxx index bbe9fd19..942c6224 100644 --- a/SHADE_Managed/src/Components/Transform.hxx +++ b/SHADE_Managed/src/Components/Transform.hxx @@ -107,30 +107,6 @@ namespace SHADE Vector3 get(); void set(Vector3 val); } - /// - /// Parent Transform that affects this Transform. - /// - property Transform^ Parent - { - Transform^ get(); - } - - /*-----------------------------------------------------------------------------*/ - /* Usage Functions */ - /*-----------------------------------------------------------------------------*/ - /// - /// Sets the parent of this Transform component. - /// - /// - /// Entity that contains the Transform component that this Transform will be - /// parented to. If null, unparenting will occur. - /// - /// - /// If true, the transform values of this Transform component will retain their - /// pre-parent-change global transforms. The local transform values will be - /// modified to ensure that the global transforms do not change. - /// - void SetParent(Transform^ parent, bool worldPositionStays); }; } diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 965e0ef2..7ceabfed 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -79,11 +79,24 @@ namespace SHADE } GameObject^ GameObject::Parent::get() { - return nullptr; + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + const auto* ROOT = SCENE_GRAPH.GetRoot(); + + const auto* NODE = SCENE_GRAPH.GetNode(entity); + if (NODE == nullptr) + throw gcnew System::InvalidOperationException("Unable to retrieve SceneGraphNode for Entity " + entity.ToString()); + + const auto* PARENT = NODE->GetParent(); + return PARENT != ROOT ? gcnew GameObject(PARENT->GetEntityID()) : nullptr; } void GameObject::Parent::set(GameObject^ newParent) { - + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + + if (newParent == nullptr) + SCENE_GRAPH.SetParent(entity, nullptr); + else + SCENE_GRAPH.SetParent(entity, newParent->EntityId); } /*---------------------------------------------------------------------------------*/ @@ -97,10 +110,6 @@ namespace SHADE { GetNativeEntity().SetActive(active); } - System::Collections::ArrayList^ GameObject::GetChildren() - { - return children; - } /*---------------------------------------------------------------------------------*/ /* Component Functions */ diff --git a/SHADE_Managed/src/Engine/GameObject.hxx b/SHADE_Managed/src/Engine/GameObject.hxx index a0b5086a..99296a91 100644 --- a/SHADE_Managed/src/Engine/GameObject.hxx +++ b/SHADE_Managed/src/Engine/GameObject.hxx @@ -93,6 +93,9 @@ namespace SHADE { Entity get(); } + /// + /// The parent entity for this GameObject. + /// property GameObject^ Parent { GameObject^ get(); @@ -117,15 +120,6 @@ namespace SHADE /// Whether to activate or deactivate this GameObject. /// void SetActive(bool active); - - /// - /// Gets the list of GameObjects that are the children of this GameObject. - /// - /// - /// The list of GameObjects that are the children of this GameObject. List is empty is - /// there is none. - /// - System::Collections::ArrayList^ GetChildren(); /*-----------------------------------------------------------------------------*/ From 97a39d62c6ab55d5655ef4a0c4d06721b204c66b Mon Sep 17 00:00:00 2001 From: Glence Date: Tue, 1 Nov 2022 23:28:31 +0800 Subject: [PATCH 4/5] player controller done for now --- TempScriptsFolder/PlayerController.cs | 85 ++++++++++++++++++--------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/TempScriptsFolder/PlayerController.cs b/TempScriptsFolder/PlayerController.cs index 98c3d3b5..0d374bae 100644 --- a/TempScriptsFolder/PlayerController.cs +++ b/TempScriptsFolder/PlayerController.cs @@ -10,7 +10,7 @@ public class PlayerController : Script IDILE, WALKING, RUNNING, - INAIR, + JUMP, FALLING, HOLDING, CAUGHT, @@ -19,26 +19,47 @@ public class PlayerController : Script private RigidBody rb; private Transform tranform; - private int xAxisMove; - private int zAxisMove; + + //to be remove public float drag = 2.0f; - private bool isMoveKeyPress = false; + [SerializeField] + [Tooltip("The current state fo the raccoon")] public RaccoonStates currentState = RaccoonStates.IDILE; + //Movement variables============================================================ + [SerializeField] + [Tooltip("Max vel for walking")] public float maxMoveVel = 2.0f; + [SerializeField] + [Tooltip("how much force is apply for walking")] public float moveForce = 50.0f; + [SerializeField] + [Tooltip("increase the moveForce and maxMoveVel by its amt")] public float sprintMultiplier = 2.0f; + private float oldForce; private float maxOldVel; private bool sprintIncreaseOnce = false; + private int xAxisMove; + private int zAxisMove; + private bool isMoveKeyPress = false; + + [SerializeField] + [Tooltip("curr not working")] public float rotationFactorPerFrame = 1.0f; - - public float initialJumpVel; - public float maxJumpHeight = 1.0f; - public float maxJumpTime = 0.5f; - private bool isJumping = false; - public bool isGrounded = true; + //Jumping vars================================================================== + [SerializeField] + [Tooltip("max height of the jump")] + public float maxJumpHeight = 4.0f; + [SerializeField] + [Tooltip("max amt of time it will take for the jump")] + public float maxJumpTime = 0.75f; + [SerializeField] + [Tooltip("increase gravity when falling")] + public float fallMultipler = 2.0f; + private float initialJumpVel; + private bool isGrounded = true; private float gravity = -9.8f; private float groundGravity = -0.5f; @@ -80,7 +101,7 @@ public class PlayerController : Script MoveKey(); - Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString()); + //Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString()); } protected override void fixedUpdate() @@ -111,10 +132,10 @@ public class PlayerController : Script isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0; - if(isMoveKeyPress && currentState != RaccoonStates.RUNNING) + if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded) currentState = RaccoonStates.WALKING; - if (!isMoveKeyPress) + if (!isMoveKeyPress && isGrounded) currentState = RaccoonStates.IDILE; } @@ -144,7 +165,7 @@ public class PlayerController : Script private void Sprint() { - if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress) + if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded) { currentState = RaccoonStates.RUNNING; if(!sprintIncreaseOnce) @@ -158,7 +179,7 @@ public class PlayerController : Script } } - if (Input.GetKeyUp(Input.KeyCode.LeftShift) && (currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)) + if (Input.GetKeyUp(Input.KeyCode.LeftShift)) { if(isMoveKeyPress) currentState = RaccoonStates.WALKING; @@ -173,23 +194,17 @@ public class PlayerController : Script { if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE) { - if (Input.GetKeyDown(Input.KeyCode.Space)&& isGrounded && rb != null) + if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null) { - isJumping = true; + currentState = RaccoonStates.JUMP; Vector3 v = rb.LinearVelocity; - v.y = initialJumpVel; + v.y = initialJumpVel * 0.5f; rb.LinearVelocity = v; } } - if (rb != null) - { - if (rb.LinearVelocity.y > 0 && isJumping) - currentState = RaccoonStates.INAIR; - else if(rb.LinearVelocity.y < 0 && isJumping) - currentState = RaccoonStates.FALLING; - - } + if(rb != null && !isGrounded && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space))) + currentState = RaccoonStates.FALLING; } private void Rotation() @@ -215,7 +230,7 @@ public class PlayerController : Script if (rb != null) { //check player vel.y if its close to zero its on the ground - if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f, 0.1f)) + if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f)) isGrounded = true; else isGrounded = false; @@ -224,8 +239,20 @@ public class PlayerController : Script if (isGrounded) v.y = groundGravity; - else - v.y += gravity * (float)Time.DeltaTime; + else if (currentState == RaccoonStates.FALLING) + { + float prevYVel = v.y; + float newYVel = v.y + (gravity * fallMultipler * (float)Time.DeltaTime); + float nextYVel = (prevYVel + newYVel) * 0.5f; + v.y = nextYVel; + } + else + { + float prevYVel = v.y; + float newYVel = v.y + (gravity * (float)Time.DeltaTime); + float nextYVel = (prevYVel + newYVel) * 0.5f; + v.y = nextYVel; + } rb.LinearVelocity = v; From 4eef6143dcfcb71ea6f38a7527e29bf139d99049 Mon Sep 17 00:00:00 2001 From: Glence Date: Wed, 2 Nov 2022 00:25:43 +0800 Subject: [PATCH 5/5] base for pick and throw --- TempScriptsFolder/PickAndThrow.cs | 30 +++++++++++++++++++++++++++ TempScriptsFolder/PlayerController.cs | 1 + 2 files changed, 31 insertions(+) create mode 100644 TempScriptsFolder/PickAndThrow.cs diff --git a/TempScriptsFolder/PickAndThrow.cs b/TempScriptsFolder/PickAndThrow.cs new file mode 100644 index 00000000..834a508c --- /dev/null +++ b/TempScriptsFolder/PickAndThrow.cs @@ -0,0 +1,30 @@ +using SHADE; +using System; +using static PlayerController; + +public class PickAndThrow : Script +{ + private PlayerController pc; + public uint itemEID; + Transform itemHoldLocation; + public PickAndThrow(GameObject gameObj) : base(gameObj) { } + protected override void awake() + { + pc = GetScript(); + itemHoldLocation = GetComponentInChildren(); + } + protected override void update() + { + if (pc != null && pc.holdItem) + { + } + } + protected override void onCollisionEnter(CollisionInfo info) + { + if (info.GameObject.Name == "item" && Input.GetKey(Input.KeyCode.E)) + { + pc.holdItem = true; + itemEID = info.GameObject.EntityId; + } + } +} \ No newline at end of file diff --git a/TempScriptsFolder/PlayerController.cs b/TempScriptsFolder/PlayerController.cs index 0d374bae..36e19860 100644 --- a/TempScriptsFolder/PlayerController.cs +++ b/TempScriptsFolder/PlayerController.cs @@ -22,6 +22,7 @@ public class PlayerController : Script //to be remove public float drag = 2.0f; + public bool holdItem = false; [SerializeField] [Tooltip("The current state fo the raccoon")] public RaccoonStates currentState = RaccoonStates.IDILE;