diff --git a/Editor/resources/Scenes/test.scene b/Editor/resources/Scenes/test.scene index 0a2e7c30..f731718d 100644 --- a/Editor/resources/Scenes/test.scene +++ b/Editor/resources/Scenes/test.scene @@ -2,12 +2,12 @@ "Entities": [ { "NameComponent": { - "ID": 130924321, + "ID": -1986865524, "Name": "testing" }, "ParentComponent": { "HasParent": true, - "ParentID": 130921466 + "ParentID": -1986867378 }, "TransformComponent": { "Rotation": { @@ -30,7 +30,7 @@ }, { "NameComponent": { - "ID": 130921466, + "ID": -1986867378, "Name": "Brush 2" }, "ParentComponent": { @@ -58,12 +58,12 @@ }, { "NameComponent": { - "ID": 130912441, + "ID": -1986874285, "Name": "TestTrigger" }, "ParentComponent": { "HasParent": true, - "ParentID": 130909903 + "ParentID": -1986876522 }, "TransformComponent": { "Rotation": { @@ -90,7 +90,7 @@ }, { "NameComponent": { - "ID": 130909903, + "ID": -1986876522, "Name": "Brush 1" }, "ParentComponent": { @@ -118,12 +118,12 @@ }, { "NameComponent": { - "ID": 126715946, + "ID": -1990960415, "Name": "" }, "ParentComponent": { "HasParent": true, - "ParentID": 126713557 + "ParentID": -1990962787 }, "TransformComponent": { "Rotation": { @@ -146,7 +146,7 @@ }, { "NameComponent": { - "ID": 126713557, + "ID": -1990962787, "Name": "Brush 0" }, "ParentComponent": { @@ -173,18 +173,9 @@ } }, { - "CameraComponent": { - "CameraInstance": { - "AspectRatio": 1.9246861934661865, - "Exposure": 1.0, - "Fov": 88.0, - "Speed": 1.0, - "m_Type": 1 - } - }, "NameComponent": { - "ID": 237481018, - "Name": "Camera" + "ID": -1598095916, + "Name": "Model" }, "ParentComponent": { "HasParent": false @@ -192,7 +183,7 @@ "TransformComponent": { "Rotation": { "x": 0.0, - "y": -0.0, + "y": 0.0, "z": 0.0 }, "Scale": { @@ -201,15 +192,11 @@ "z": 1.0 }, "Translation": { - "x": 6.100314617156982, - "y": -49.37096405029297, - "z": -5.69704008102417 + "x": 0.0, + "y": 0.0, + "z": 0.0 }, "Type": "TransformComponent" - }, - "WrenScriptComponent": { - "Class": "CamScript", - "Script": "Scripts/Cam.wren" } }, { @@ -328,9 +315,18 @@ } }, { + "CameraComponent": { + "CameraInstance": { + "AspectRatio": 1.9246861934661865, + "Exposure": 1.0, + "Fov": 88.0, + "Speed": 1.0, + "m_Type": 1 + } + }, "NameComponent": { - "ID": -1598095916, - "Name": "Model" + "ID": 237481018, + "Name": "Camera" }, "ParentComponent": { "HasParent": false @@ -338,7 +334,7 @@ "TransformComponent": { "Rotation": { "x": 0.0, - "y": 0.0, + "y": -0.0, "z": 0.0 }, "Scale": { @@ -347,11 +343,15 @@ "z": 1.0 }, "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 + "x": 6.100314617156982, + "y": -49.37096405029297, + "z": -5.69704008102417 }, "Type": "TransformComponent" + }, + "WrenScriptComponent": { + "Class": "CamScript", + "Script": "Scripts/Cam.wren" } } ], diff --git a/Editor/resources/Scripts/Cam.wren b/Editor/resources/Scripts/Cam.wren index d5b2f597..35487cf3 100644 --- a/Editor/resources/Scripts/Cam.wren +++ b/Editor/resources/Scripts/Cam.wren @@ -76,5 +76,9 @@ class CamScript is ScriptableEntity { cam.SetDirection(newDir) } + fixedUpdate(ts) { + + } + exit() {} } \ No newline at end of file diff --git a/Editor/resources/Scripts/Scene.wren b/Editor/resources/Scripts/Scene.wren index 72b0c58e..6d56c112 100644 --- a/Editor/resources/Scripts/Scene.wren +++ b/Editor/resources/Scripts/Scene.wren @@ -204,6 +204,7 @@ class Brush { var entities = [] var targets = Scene.BrushGetTargets_(_entityId) + for(t in targets) { entities.add(Entity.new(t)) } diff --git a/Editor/resources/Scripts/Trigger.wren b/Editor/resources/Scripts/Trigger.wren index c5ccf6d9..370942ae 100644 --- a/Editor/resources/Scripts/Trigger.wren +++ b/Editor/resources/Scripts/Trigger.wren @@ -18,7 +18,7 @@ class TriggerScript is ScriptableEntity { fixedUpdate(ts) { var trigger = this.GetComponent("Trigger") - Engine.Log("Hello") + if(trigger.GetOverlappingBodyCount() > 0) { var bodies = trigger.GetOverlappingBodies() var brush = this.GetComponent("Brush") @@ -32,7 +32,7 @@ class TriggerScript is ScriptableEntity { for(t in brush.GetTargets()) { var transform = t.GetComponent("Transform") var pos = transform.GetTranslation() - Engine.Log("Hello") + pos.x = pos.x + 1.0 * ts transform.SetTranslation(pos) diff --git a/Editor/resources/Scripts/entityScript.wren b/Editor/resources/Scripts/entityScript.wren index a5fe55d4..3a3088a1 100644 --- a/Editor/resources/Scripts/entityScript.wren +++ b/Editor/resources/Scripts/entityScript.wren @@ -15,6 +15,10 @@ class TestScript is ScriptableEntity { _deltaTime = _deltaTime + ts + } + + fixedUpdate(ts) { + } exit() { diff --git a/Nuake/src/Core/Physics/CharacterController.cpp b/Nuake/src/Core/Physics/CharacterController.cpp index daece1fc..d169b7af 100644 --- a/Nuake/src/Core/Physics/CharacterController.cpp +++ b/Nuake/src/Core/Physics/CharacterController.cpp @@ -3,8 +3,6 @@ #include "../Core/Physics/RaycastResult.h" namespace Physics { - - CharacterController::CharacterController(float height, float radius, float mass, Vector3 position) { m_surfaceHitNormals = std::vector(); @@ -55,6 +53,8 @@ namespace Physics m_GhostObject->setUserIndex(ent.GetHandle()); } + + void CharacterController::MoveAndSlide(glm::vec3 velocity) { m_Rigidbody->setGravity(btVector3(0, 0, 0)); @@ -63,7 +63,6 @@ namespace Physics m_GhostObject->setWorldTransform(m_Rigidbody->getWorldTransform()); IsOnGround = false; - ParseGhostContacts(); UpdatePosition(); UpdateVelocity(); @@ -100,8 +99,7 @@ namespace Physics // Skip the rigid body the ghost monitors if (pManifold->getBody0() == m_Rigidbody) continue; - btVector3 boost = pManifold->getBody0()->getInterpolationLinearVelocity(); - m_manualVelocity += Vector3(boost.x(), boost.y(), boost.z()); + for (int p = 0; p < pManifold->getNumContacts(); p++) { const btManifoldPoint& point = pManifold->getContactPoint(p); @@ -144,12 +142,12 @@ namespace Physics { float previousY = m_Rigidbody->getWorldTransform().getOrigin().getY(); + float t = rayCallBack_bottom.m_closestHitFraction ; float clamped = (1.0 - rayCallBack_bottom.m_closestHitFraction); btVector3 vel(m_Rigidbody->getLinearVelocity()); - if(vel.getY() < 0) // -magic number is to fix bouncing down a slope. m_Rigidbody->getWorldTransform().getOrigin().setY(previousY - 0.14f + (m_bottomYOffset + m_stepHeight) * (clamped)); @@ -160,7 +158,7 @@ namespace Physics IsOnGround = true; } - + float testOffset = 0.07f; diff --git a/Nuake/src/Core/Physics/CharacterController.h b/Nuake/src/Core/Physics/CharacterController.h index 05de355f..43c2c2e4 100644 --- a/Nuake/src/Core/Physics/CharacterController.h +++ b/Nuake/src/Core/Physics/CharacterController.h @@ -42,6 +42,12 @@ namespace Physics void SetEntity(Entity& ent); void MoveAndSlide(glm::vec3 velocity); + + bool IsOnFloor() + { + return IsOnGround; + } + private: void ParseGhostContacts(); void UpdatePosition(); diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index b0dcabb6..3c2c9d08 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -71,7 +71,6 @@ void PhysicsSystem::Init() PhysicsManager::Get()->RegisterBody(btRigidbody); } } - } auto bspTriggerView = m_Scene->m_Registry.view(); diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index 46bd5580..e52b260b 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -285,18 +285,25 @@ void QuakeMapBuilder::CreateFuncBrush(brush* brush, brush_geometry* brush_inst, indices.push_back(index_offset + (unsigned int)index); } - if (lastTextureID != face->texture_idx) + if(!bsp.IsTrigger) { - lastTexturePath = "resources/Textures/" + std::string(texture->name) + ".png"; - if (std::string(texture->name) == "__TB_empty") - bsp.Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); - else - bsp.Meshes.push_back(CreateRef(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath))); + if (lastTextureID != face->texture_idx) + { + lastTexturePath = "resources/Textures/" + std::string(texture->name) + ".png"; + if (std::string(texture->name) == "__TB_empty") + bsp.Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); + else + bsp.Meshes.push_back(CreateRef(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath))); - index_offset = 0; - vertices.clear(); - indices.clear(); - lastTextureID = face->texture_idx; + index_offset = 0; + vertices.clear(); + indices.clear(); + lastTextureID = face->texture_idx; + } + else + { + index_offset += (face_geo_inst->vertex_count); + } } else { @@ -304,6 +311,12 @@ void QuakeMapBuilder::CreateFuncBrush(brush* brush, brush_geometry* brush_inst, } } + if (bsp.IsTrigger) + { + bsp.Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); + vertices.clear(); + } + if (vertices.size() > 0) bsp.Meshes.push_back(CreateRef(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath))); } diff --git a/Nuake/src/Scripting/Modules/SceneModule.h b/Nuake/src/Scripting/Modules/SceneModule.h index a408615a..9f072750 100644 --- a/Nuake/src/Scripting/Modules/SceneModule.h +++ b/Nuake/src/Scripting/Modules/SceneModule.h @@ -244,6 +244,7 @@ namespace ScriptAPI float x = wrenGetSlotDouble(vm, 2); float y = wrenGetSlotDouble(vm, 3); float z = wrenGetSlotDouble(vm, 4); + transform.Translation = Vector3(x, y, z); }