diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index cc63c565..f3760b4d 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -157,7 +157,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::Checkbox("##", &value); + return ImGui::Checkbox("#", &value); } bool SHEditorUI::InputInt(const std::string& label, int& value, bool* isHovered) { @@ -165,7 +165,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::InputInt("##", &value, + return ImGui::InputInt("#", &value, 1, 10, ImGuiInputTextFlags_EnterReturnsTrue); } @@ -176,7 +176,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - const bool CHANGED = InputInt("##", signedVal); + const bool CHANGED = InputInt("#", signedVal); if (CHANGED) { signedVal = std::clamp(signedVal, 0, std::numeric_limits::max()); @@ -190,7 +190,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::InputFloat("##", &value, + return ImGui::InputFloat("#", &value, 0.1f, 1.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue); } @@ -200,7 +200,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::InputDouble("##", &value, + return ImGui::InputDouble("#", &value, 0.1, 1.0, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue); } @@ -210,7 +210,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::InputDouble("##", &value, + return ImGui::InputDouble("#", &value, 1.0, 45.0, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue); } @@ -280,7 +280,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - const bool CHANGED = ImGui::InputText("##", &buffer[0], TEXT_FIELD_MAX_LENGTH); + const bool CHANGED = ImGui::InputText("#", &buffer[0], TEXT_FIELD_MAX_LENGTH); if (CHANGED) { value = std::string(buffer.data(), buffer.data() + TEXT_FIELD_MAX_LENGTH); @@ -327,7 +327,7 @@ namespace SHADE if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - if (ImGui::BeginCombo("##", INITIAL_NAME.c_str(), ImGuiComboFlags_None)) + if (ImGui::BeginCombo("#", INITIAL_NAME.c_str(), ImGuiComboFlags_None)) { for (int i = 0; i < enumNames.size(); ++i) { diff --git a/SHADE_Managed/src/Components/RigidBody.cxx b/SHADE_Managed/src/Components/RigidBody.cxx index 12861600..172b928b 100644 --- a/SHADE_Managed/src/Components/RigidBody.cxx +++ b/SHADE_Managed/src/Components/RigidBody.cxx @@ -148,14 +148,6 @@ namespace SHADE { return Convert::ToCLI(GetNativeComponent()->GetTorque()); } - bool RigidBody::Interpolating::get() - { - return GetNativeComponent()->IsInterpolating(); - } - void RigidBody::Interpolating::set(bool value) - { - GetNativeComponent()->SetInterpolate(value); - } /*---------------------------------------------------------------------------------*/ /* Force Functions */ diff --git a/SHADE_Managed/src/Components/RigidBody.hxx b/SHADE_Managed/src/Components/RigidBody.hxx index d3a30612..b3e031ba 100644 --- a/SHADE_Managed/src/Components/RigidBody.hxx +++ b/SHADE_Managed/src/Components/RigidBody.hxx @@ -129,11 +129,6 @@ namespace SHADE { Vector3 get(); } - property bool Interpolating - { - bool get(); - void set(bool value); - } /*-----------------------------------------------------------------------------*/ /* Force Functions */ diff --git a/TempScriptsFolder/AIPrototype.cs b/TempScriptsFolder/AIPrototype.cs new file mode 100644 index 00000000..88a319e3 --- /dev/null +++ b/TempScriptsFolder/AIPrototype.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using SHADE; + +public class AIPrototype : Script +{ + //This object's relevant components + private Transform transform; + private RigidBody rb; + + /*[SerializeField] + [Tooltip("The list of waypoints that the object will move around on")] + private Vector3[] waypoints;*/ + + private Vector3[] waypoints = { new Vector3(2.0f, -2.0f, -2.8f), new Vector3(-2.0f, -2.0f, -2.8f), new Vector3(-2.0f, -2.0f, -7.0f), new Vector3(2.0f, -2.0f, -7.0f) }; + + [SerializeField] + [Tooltip("How much force is applied in movement")] + private float movementForceMultiplier = 100.0f; + + [SerializeField] + [Tooltip("How fast the object moves about waypoints")] + private float patrolSpeed = 1.0f; + + [SerializeField] + [Tooltip("How fast the object moves while chasing")] + private float chaseSpeed = 1.5f; + + [SerializeField] + [Tooltip("How near the player must be for the chase to begin. Should be less than distanceToEndChase")] + private float distanceToStartChase = 1.5f; + + [SerializeField] + [Tooltip("How far the player must be for the chase to end. Should be greater than distanceToStartChase")] + private float distanceToEndChase = 2.5f; + + //Whether the AI is chasing or not + private bool chaseMode; + + //To cycle depending on the length of waypoints + private int currentTargetWaypointIndex; + + private GameObject? player; + + public AIPrototype(GameObject gameObj) : base(gameObj) { } + + protected override void awake() + { + transform = GetComponent(); + if (transform == null) + { + Debug.LogError("Transform is NULL!"); + } + + rb = GetComponent(); + if (rb == null) + { + Debug.LogError("Rigidbody is NULL!"); + } + + currentTargetWaypointIndex = 0; + + player = GameObject.Find("Player"); + if (player == null) + { + Debug.LogError("Player is NULL!"); + } + + chaseMode = false; + } + + protected override void fixedUpdate() + { + //Patrolling + if (!chaseMode) + { + //Head towards the next target + Vector3 normalisedDifference = waypoints[currentTargetWaypointIndex] - transform.GlobalPosition; + normalisedDifference /= normalisedDifference.GetMagnitude(); + + //transform.GlobalPosition += normalisedDifference * moveSpeed * (float)Time.DeltaTime; + //rb.LinearVelocity = normalisedDifference * patrolSpeed; + + //ORIGINAL INTENDED CODE + /*rb.AddForce(new Vector3(normalisedDifference.x, 0.0f, normalisedDifference.z) * movementForceMultiplier); + float currentSpeed = MathF.Sqrt(rb.LinearVelocity.x * rb.LinearVelocity.x + rb.LinearVelocity.z * rb.LinearVelocity.z); + if (currentSpeed > patrolSpeed) + { + float adjustmentFactor = patrolSpeed / currentSpeed; + Vector3 adjustedVelocity = rb.LinearVelocity; + //adjustedVelocity *= adjustmentFactor; + adjustedVelocity.x = patrolSpeed; + adjustedVelocity.z = patrolSpeed; + rb.LinearVelocity = adjustedVelocity; + }*/ + + //TODO delete this when original intended code above works with velocity being limited correctly + rb.LinearVelocity = normalisedDifference * patrolSpeed; + + //transform.GlobalRotation.SetLookRotation(waypoints[currentTargetWaypointIndex], Vector3.Up); + + //Cycle to next waypoint if near enough current waypoint + if ((waypoints[currentTargetWaypointIndex] - transform.GlobalPosition).GetSqrMagnitude() <= 0.5f) + { + ++currentTargetWaypointIndex; + if (currentTargetWaypointIndex >= waypoints.Length) + { + currentTargetWaypointIndex = 0; //Recycle + } + } + + //Go chase if near enough to player + if (player != null) + { + Transform pTransform = player.GetValueOrDefault().GetComponent(); + if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() <= distanceToStartChase) + { + //Start the chase + chaseMode = true; + } + } + } + else //Chasing + { + if (player != null) + { + Transform pTransform = player.GetValueOrDefault().GetComponent(); + + //Chase the player + Vector3 normalisedDifference = pTransform.GlobalPosition - transform.GlobalPosition; + normalisedDifference /= normalisedDifference.GetMagnitude(); + + //transform.GlobalPosition += normalisedDifference * moveSpeed * (float)Time.DeltaTime; + + //ORIGINAL INTENDED CODE + /*rb.AddForce(new Vector3(normalisedDifference.x, 0.0f, normalisedDifference.z) * movementForceMultiplier); + float currentSpeed = MathF.Sqrt(rb.LinearVelocity.x * rb.LinearVelocity.x + rb.LinearVelocity.z * rb.LinearVelocity.z); + if (currentSpeed > chaseSpeed) + { + float adjustmentFactor = chaseSpeed / currentSpeed; + Vector3 adjustedVelocity = rb.LinearVelocity; + adjustedVelocity *= adjustmentFactor; + rb.LinearVelocity = adjustedVelocity; + }*/ + + //TODO delete this when original intended code above works with velocity being limited correctly + rb.LinearVelocity = normalisedDifference * chaseSpeed; + + //End chase if too far + if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() >= distanceToEndChase) + { + //Stop the chase + chaseMode = false; + + //Find the nearest waypoint to go instead + float nearestWaypointDistance = 99999999999999.9f; + for (int i = 0; i < waypoints.Length; ++i) + { + if ((waypoints[i] - transform.GlobalPosition).GetSqrMagnitude() < nearestWaypointDistance) + { + nearestWaypointDistance = waypoints[i].GetSqrMagnitude(); + currentTargetWaypointIndex = i; + } + } + } + } + } + } +} \ No newline at end of file