diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 4777fc6a..12893de6 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -244,9 +244,12 @@ namespace SHADE SHCollider* collider = &component->GetCollider(i); auto cursorPos = ImGui::GetCursorPos(); + //collider->IsTrigger + if (collider->GetType() == SHCollider::Type::BOX) { SHEditorWidgets::BeginPanel(std::format("{} Box Collider #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); + SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); auto box = reinterpret_cast(collider->GetShape()); SHEditorWidgets::DragVec3 ( @@ -257,6 +260,7 @@ namespace SHADE else if (collider->GetType() == SHCollider::Type::SPHERE) { SHEditorWidgets::BeginPanel(std::format("{} Sphere Collider #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); + SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); auto sphere = reinterpret_cast(collider->GetShape()); SHEditorWidgets::DragFloat ( diff --git a/SHADE_Managed/src/Components/Camera.cxx b/SHADE_Managed/src/Components/Camera.cxx index 5e570cc1..0d0dbced 100644 --- a/SHADE_Managed/src/Components/Camera.cxx +++ b/SHADE_Managed/src/Components/Camera.cxx @@ -123,5 +123,14 @@ namespace SHADE } + Vector3 Camera::GetRight() + { + auto system = SHSystemManager::GetSystem(); + SHVec3 forward, up, right; + system->GetCameraAxis(*GetNativeComponent(), forward, right, up); + return Convert::ToCLI(right); + + } + } \ No newline at end of file diff --git a/SHADE_Managed/src/Components/Camera.hxx b/SHADE_Managed/src/Components/Camera.hxx index 257bff11..c6afeb6d 100644 --- a/SHADE_Managed/src/Components/Camera.hxx +++ b/SHADE_Managed/src/Components/Camera.hxx @@ -66,5 +66,7 @@ namespace SHADE void SetMainCamera(); void LookAt(Vector3 targetPosition); Vector3 GetForward(); + Vector3 GetRight(); + }; } \ No newline at end of file diff --git a/TempScriptsFolder/PickAndThrow.cs b/TempScriptsFolder/PickAndThrow.cs index 834a508c..09252247 100644 --- a/TempScriptsFolder/PickAndThrow.cs +++ b/TempScriptsFolder/PickAndThrow.cs @@ -5,26 +5,94 @@ using static PlayerController; public class PickAndThrow : Script { private PlayerController pc; - public uint itemEID; - Transform itemHoldLocation; + public GameObject item; + public Vector3 throwForce = new Vector3(200.0f, 300.0f, 200.0f); + private Transform itemTransform; + private RigidBody itemRidibody; + private Transform raccoonHoldLocation; + private float lastXDir; + private float lastZDir; + private bool inRange = false; public PickAndThrow(GameObject gameObj) : base(gameObj) { } + protected override void awake() { pc = GetScript(); - itemHoldLocation = GetComponentInChildren(); + raccoonHoldLocation = GetComponentInChildren(); + if (raccoonHoldLocation == null) + Debug.Log("CHILD EMPTY"); + itemTransform = item.GetComponent(); + if (itemTransform == null) + Debug.Log("Item transform EMPTY"); + itemRidibody = item.GetComponent(); + if (itemRidibody == null) + Debug.Log("Item rb EMPTY"); } protected override void update() { - if (pc != null && pc.holdItem) + if (!pc.isMoveKeyPress) { + if (pc.xAxisMove != 0) + { + lastXDir = pc.xAxisMove; + lastZDir = 0.0f; + } + if (pc.zAxisMove != 0) + { + lastXDir = 0.0f; + lastZDir = pc.zAxisMove; + } } + else + { + lastXDir = pc.xAxisMove; + lastZDir = pc.zAxisMove; + } + + if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E)) + pc.holdItem = true; + + if (pc != null && itemRidibody != null && itemTransform!= null && pc.holdItem) + { + itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition; + itemRidibody.IsGravityEnabled = false; + itemRidibody.LinearVelocity = Vector3.Zero; + itemRidibody.AngularVelocity = Vector3.Zero; + + if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) + { + pc.holdItem = false; + itemRidibody.IsGravityEnabled = true; + itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir)); + itemRidibody.LinearVelocity += pc.rb.LinearVelocity; + Debug.Log($"x: {itemRidibody.LinearVelocity.x} z: {itemRidibody.LinearVelocity.z}"); + } + } + else if(!pc.holdItem) + itemRidibody.IsGravityEnabled = true; } protected override void onCollisionEnter(CollisionInfo info) { - if (info.GameObject.Name == "item" && Input.GetKey(Input.KeyCode.E)) + } + protected override void onTriggerEnter(CollisionInfo info) + { + Debug.Log("ENTER"); + if (info.GameObject == item && !pc.holdItem) { - pc.holdItem = true; - itemEID = info.GameObject.EntityId; + inRange = true; } } + protected override void onTriggerStay(CollisionInfo info) + { + Debug.Log("STAY"); + } + protected override void onTriggerExit(CollisionInfo info) + { + Debug.Log("EXIT"); + if (info.GameObject == item && !pc.holdItem) + { + inRange = false; + } + } + } \ No newline at end of file diff --git a/TempScriptsFolder/PlayerController.cs b/TempScriptsFolder/PlayerController.cs index 36e19860..5566c411 100644 --- a/TempScriptsFolder/PlayerController.cs +++ b/TempScriptsFolder/PlayerController.cs @@ -12,17 +12,17 @@ public class PlayerController : Script RUNNING, JUMP, FALLING, - HOLDING, CAUGHT, TOTAL } - private RigidBody rb; + public RigidBody rb; private Transform tranform; + private Camera cam; //to be remove public float drag = 2.0f; - public bool holdItem = false; + public bool holdItem { get; set; } [SerializeField] [Tooltip("The current state fo the raccoon")] public RaccoonStates currentState = RaccoonStates.IDILE; @@ -41,9 +41,11 @@ public class PlayerController : Script private float oldForce; private float maxOldVel; private bool sprintIncreaseOnce = false; - private int xAxisMove; - private int zAxisMove; - private bool isMoveKeyPress = false; + + public float xAxisMove { get; set; } + public float zAxisMove { get; set; } + + public bool isMoveKeyPress { get; set; } [SerializeField] [Tooltip("curr not working")] @@ -68,12 +70,21 @@ public class PlayerController : Script protected override void awake() { + + isMoveKeyPress = false; + holdItem = false; //rigidbody check rb = GetComponent(); if (rb == null) Debug.LogError("RigidBody is NULL!"); else + { + rb.IsGravityEnabled = false; + rb.FreezeRotationX = true; + rb.FreezeRotationY = true; + rb.FreezeRotationZ = true; rb.Drag = drag; + } //Transform check tranform = GetComponent(); @@ -92,6 +103,9 @@ public class PlayerController : Script protected override void update() { + if (cam == null) + cam = GetComponentInChildren(); + //toRemove if (Input.GetKey(Input.KeyCode.G)) { @@ -117,20 +131,55 @@ public class PlayerController : Script private void MoveKey() { - if (Input.GetKey(Input.KeyCode.A)) - xAxisMove = -1; - else if (Input.GetKey(Input.KeyCode.D)) - xAxisMove = 1; - else - xAxisMove = 0; + /* if (Input.GetKey(Input.KeyCode.A)) + xAxisMove = -1; + else if (Input.GetKey(Input.KeyCode.D)) + xAxisMove = 1; + else + xAxisMove = 0; + if (Input.GetKey(Input.KeyCode.W)) + zAxisMove = -1; + else if (Input.GetKey(Input.KeyCode.S)) + zAxisMove = 1; + else + zAxisMove = 0;*/ + + + xAxisMove = 0; + zAxisMove = 0; if (Input.GetKey(Input.KeyCode.W)) - zAxisMove = -1; - else if (Input.GetKey(Input.KeyCode.S)) - zAxisMove = 1; - else - zAxisMove = 0; - + { + Vector3 camerAixs = cam.GetForward(); + camerAixs.y = 0; + camerAixs.Normalise(); + xAxisMove = camerAixs.x; + zAxisMove = camerAixs.z; + } + if (Input.GetKey(Input.KeyCode.S)) + { + Vector3 camerAixs = cam.GetForward(); + camerAixs.y = 0; + camerAixs.Normalise(); + xAxisMove = -camerAixs.x; + zAxisMove = -camerAixs.z; + } + if (Input.GetKey(Input.KeyCode.A)) + { + Vector3 camerAixs = cam.GetRight(); + camerAixs.y = 0; + camerAixs.Normalise(); + xAxisMove = -camerAixs.x; + zAxisMove = -camerAixs.z; + } + if (Input.GetKey(Input.KeyCode.D)) + { + Vector3 camerAixs = cam.GetRight(); + camerAixs.y = 0; + camerAixs.Normalise(); + xAxisMove = camerAixs.x; + zAxisMove = camerAixs.z; + } isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0; if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded) @@ -169,7 +218,8 @@ public class PlayerController : Script if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded) { currentState = RaccoonStates.RUNNING; - if(!sprintIncreaseOnce) + holdItem = false; + if (!sprintIncreaseOnce) { sprintIncreaseOnce = true; oldForce = moveForce; diff --git a/TempScriptsFolder/ThirdPersonCamera.cs b/TempScriptsFolder/ThirdPersonCamera.cs index e3b043bd..618c562f 100644 --- a/TempScriptsFolder/ThirdPersonCamera.cs +++ b/TempScriptsFolder/ThirdPersonCamera.cs @@ -19,10 +19,13 @@ namespace SHADE_Scripting protected override void awake() { + AddComponent(); + if(!GetComponent()) { AddComponent(); } + GetComponent().SetMainCamera(); if (!GetComponent()) { AddComponent(); @@ -30,26 +33,29 @@ namespace SHADE_Scripting GetComponent().ArmLength = armLength; } - protected override void update() - { - CameraArm arm = GetComponent(); - if(arm) + protected override void update() + { + if (Input.GetMouseButton(Input.MouseCode.RightButton)) + { + CameraArm arm = GetComponent(); + if (arm) + { + Vector2 vel = Input.GetMouseVelocity(); + arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; + arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; + + if (arm.Pitch > pitchClamp) { - Vector2 vel = Input.GetMouseVelocity(); - arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; - arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; - - if(arm.Pitch > pitchClamp) - { - arm.Pitch = pitchClamp; - } - else if(arm.Pitch < -pitchClamp) - { - arm.Pitch = -pitchClamp; - } - + arm.Pitch = pitchClamp; } + else if (arm.Pitch < 0) + { + arm.Pitch = 0; + } + + } } + } } }