mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-04 11:35:06 +03:00
Fixed triggers mesh collision to account for all faces
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -76,5 +76,9 @@ class CamScript is ScriptableEntity {
|
||||
cam.SetDirection(newDir)
|
||||
}
|
||||
|
||||
fixedUpdate(ts) {
|
||||
|
||||
}
|
||||
|
||||
exit() {}
|
||||
}
|
||||
@@ -204,6 +204,7 @@ class Brush {
|
||||
|
||||
var entities = []
|
||||
var targets = Scene.BrushGetTargets_(_entityId)
|
||||
|
||||
for(t in targets) {
|
||||
entities.add(Entity.new(t))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -15,6 +15,10 @@ class TestScript is ScriptableEntity {
|
||||
_deltaTime = _deltaTime + ts
|
||||
|
||||
|
||||
}
|
||||
|
||||
fixedUpdate(ts) {
|
||||
|
||||
}
|
||||
|
||||
exit() {
|
||||
|
||||
@@ -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<glm::vec3>();
|
||||
@@ -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;
|
||||
|
||||
@@ -42,6 +42,12 @@ namespace Physics
|
||||
|
||||
void SetEntity(Entity& ent);
|
||||
void MoveAndSlide(glm::vec3 velocity);
|
||||
|
||||
bool IsOnFloor()
|
||||
{
|
||||
return IsOnGround;
|
||||
}
|
||||
|
||||
private:
|
||||
void ParseGhostContacts();
|
||||
void UpdatePosition();
|
||||
|
||||
@@ -71,7 +71,6 @@ void PhysicsSystem::Init()
|
||||
PhysicsManager::Get()->RegisterBody(btRigidbody);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto bspTriggerView = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent, TriggerZone>();
|
||||
|
||||
@@ -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<Mesh>(vertices, indices, DefaultMaterial));
|
||||
else
|
||||
bsp.Meshes.push_back(CreateRef<Mesh>(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<Mesh>(vertices, indices, DefaultMaterial));
|
||||
else
|
||||
bsp.Meshes.push_back(CreateRef<Mesh>(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<Mesh>(vertices, indices, DefaultMaterial));
|
||||
vertices.clear();
|
||||
}
|
||||
|
||||
if (vertices.size() > 0)
|
||||
bsp.Meshes.push_back(CreateRef<Mesh>(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath)));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user