diff --git a/Nuake/src/Physics/DynamicWorld.cpp b/Nuake/src/Physics/DynamicWorld.cpp index d3d85df5..5df4920e 100644 --- a/Nuake/src/Physics/DynamicWorld.cpp +++ b/Nuake/src/Physics/DynamicWorld.cpp @@ -538,9 +538,11 @@ namespace Nuake _JoltBodyInterface->MoveKinematic(bodyId, newPosition, newRotation, Engine::GetFixedTimeStep()); break; } + case JPH::EMotionType::Dynamic: case JPH::EMotionType::Static: { _JoltBodyInterface->SetPositionAndRotation(bodyId, newPosition, newRotation, JPH::EActivation::DontActivate); + break; } } @@ -579,16 +581,18 @@ namespace Nuake // Format result for (int i = 0; i < num_hits; ++i) { - const float hitFraction = results[i].mFraction; - const JPH::Vec3& hitPosition = ray.GetPointOnRay(results[i].mFraction); - auto bodyId = static_cast(results[i].mBodyID); + const float hitFraction = collector.mHits[i].mFraction; + const JPH::Vec3& hitPosition = ray.GetPointOnRay(collector.mHits[i].mFraction); + auto bodyId = static_cast(collector.mHits[i].mBodyID); auto layer = _JoltBodyInterface->GetObjectLayer(bodyId); + int userData = static_cast(_JoltBodyInterface->GetUserData(bodyId)); ShapeCastResult result { Vector3(hitPosition.GetX(), hitPosition.GetY(), hitPosition.GetZ()), hitFraction, Vector3(0, 0, 0), - layer + layer, + userData }; raycastResults.push_back(std::move(result)); @@ -637,12 +641,14 @@ namespace Nuake auto layer = _JoltBodyInterface->GetObjectLayer(bodyId); + int userData = static_cast(_JoltBodyInterface->GetUserData(bodyId)); ShapeCastResult result { Vector3(hitPosition.GetX(), hitPosition.GetY(), hitPosition.GetZ()), hitFraction, Vector3(surfaceNormal.GetX(), surfaceNormal.GetY(), surfaceNormal.GetZ()), - static_cast(layer) + static_cast(layer), + userData }; shapecastResults.push_back(std::move(result)); diff --git a/Nuake/src/Physics/RaycastResult.h b/Nuake/src/Physics/RaycastResult.h index 4b5a1aeb..0f07f1f2 100644 --- a/Nuake/src/Physics/RaycastResult.h +++ b/Nuake/src/Physics/RaycastResult.h @@ -20,5 +20,6 @@ namespace Nuake float Fraction; Vector3 ImpactNormal; float Layer; + int EntityID; }; } diff --git a/Nuake/src/Scene/Components/LightComponent.h b/Nuake/src/Scene/Components/LightComponent.h index a7d9e8a4..b29cfb4c 100644 --- a/Nuake/src/Scene/Components/LightComponent.h +++ b/Nuake/src/Scene/Components/LightComponent.h @@ -171,6 +171,8 @@ namespace Nuake SERIALIZE_VAL(Strength); SERIALIZE_VAL(SyncDirectionWithSky); SERIALIZE_VAL(CastShadows); + SERIALIZE_VAL(Cutoff); + SERIALIZE_VAL(OuterCutoff); END_SERIALIZE(); } @@ -196,6 +198,9 @@ namespace Nuake this->Direction = Vector3(x, y, z); } + DESERIALIZE_VAL(Cutoff); + DESERIALIZE_VAL(OuterCutoff); + return true; } }; diff --git a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp index 551fb7eb..e7cfd988 100644 --- a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp @@ -73,6 +73,7 @@ namespace Nuake { results.push_back(hit.ImpactNormal.z); results.push_back(hit.Fraction); results.push_back(hit.Layer); + results.push_back(hit.EntityID); } return Coral::Array::New(results); diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index c1d30f28..1c394158 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -27,6 +27,7 @@ #include #include +#include namespace Nuake { @@ -316,7 +317,7 @@ namespace Nuake { PhysicsManager::Get().SetCharacterControllerPosition(entity, { x, y, z }); } - if (entity.HasComponent()) + if (entity.HasComponent() || entity.HasComponent()) { PhysicsManager::Get().SetBodyTransform(entity, { x, y, z }, component.GetGlobalRotation()); } @@ -343,7 +344,7 @@ namespace Nuake { if (entity.IsValid() && entity.HasComponent()) { auto& component = entity.GetComponent(); - const auto& globalPosition = component.GetGlobalPosition(); + const Vector3& globalPosition = component.GlobalTransform[3]; Coral::Array result = Coral::Array::New({ globalPosition.x, globalPosition.y, globalPosition.z }); return result; } diff --git a/NuakeNet/src/Physic.cs b/NuakeNet/src/Physic.cs index c5a65219..98439192 100644 --- a/NuakeNet/src/Physic.cs +++ b/NuakeNet/src/Physic.cs @@ -95,6 +95,7 @@ namespace Nuake.Net public Vector3 ImpactNormal; public float Fraction; public Layers Layer; + public Entity Collider; } public struct BoxInternal { @@ -131,15 +132,29 @@ namespace Nuake.Net unsafe { NativeArray resultICall = RayCastIcall(from.X, from.Y, from.Z, to.X, to.Y, to.Z); - for (int i = 0; i < resultICall.Length / 7; i++) + for (int i = 0; i < resultICall.Length / 9; i++) { - int index = i * 7; + int index = i * 9; + int entityId = (int)resultICall[index + 8]; + + bool hasInstance = Entity.EntityHasManagedInstanceIcall(entityId); + Entity entityInstance; + if (hasInstance) + { + entityInstance = Scene.GetEntity(entityId); + } + else + { + entityInstance = new Entity(entityId); + } + ShapeCastResult shapeCastResult = new() { ImpactPosition = new Vector3(resultICall[index + 0], resultICall[index + 1], resultICall[index + 2]), ImpactNormal = new Vector3(resultICall[index + 3], resultICall[index + 4], resultICall[index + 5]), Fraction = resultICall[index + 6], - Layer = (Layers)resultICall[index + 7] + Layer = (Layers)resultICall[index + 7], + Collider = entityInstance }; result.Add(shapeCastResult); @@ -164,15 +179,15 @@ namespace Nuake.Net { NativeArray resultICall = ShapeCastBoxIcall(from.X, from.Y, from.Z, to.X, to.Y, to.Z, boxInternal); - for (int i = 0; i < resultICall.Length / 7; i++) + for (int i = 0; i < resultICall.Length / 8; i++) { - int index = i * 7; + int index = i * 8; ShapeCastResult shapeCastResult = new() { ImpactPosition = new Vector3(resultICall[index + 0], resultICall[index + 1], resultICall[index + 2]), ImpactNormal = new Vector3(resultICall[index + 3], resultICall[index + 4], resultICall[index + 5]), Fraction = resultICall[index + 6], - Layer = (Layers)resultICall[index + 7] + Layer = (Layers)resultICall[index + 7], }; result.Add(shapeCastResult);