feat: add moving platform support + fix jolt

This commit is contained in:
2026-10-18 13:34:30 +02:00
parent 65a7310b56
commit 7223e9ce07
15 changed files with 291 additions and 34 deletions
+42 -1
View File
@@ -19,6 +19,7 @@
#include <components/Door.h>
#include <components/InteractableButton.h>
#include <components/LightToggle.h>
#include <components/MovingPlatform.h>
#include <components/TriggerLoggerComponent.h>
#include <glm/gtc/constants.hpp>
@@ -26,6 +27,7 @@
#include <spdlog/spdlog.h>
#include <cmath>
#include <memory>
#include <optional>
#include <string>
@@ -124,10 +126,12 @@ namespace {
GameObject* CreateBox(Scene& scene, GfxDevice& gfxDevice, RenderResources& resources,
const std::string& name, const glm::vec3& position, const glm::vec3& size,
MaterialID materialID, RigidbodyType type)
MaterialID materialID, RigidbodyType type,
const glm::quat& rotation = glm::quat{1.0f, 0.0f, 0.0f, 0.0f})
{
GameObject* box = scene.CreateGameObject(name);
box->GetTransform().SetWorldPosition(position);
box->GetTransform().SetWorldRotation(rotation);
auto* boxMeshComp = box->AddComponent<MeshRendererComponent>();
boxMeshComp->SetMeshID(resources.meshes().addMesh(gfxDevice, PrimitiveMeshes::MakeBox(size)));
@@ -221,6 +225,42 @@ namespace {
button->AddComponent<InteractableButton>()->AddTarget(target);
}
void CreateMovingPlatform(Scene& scene, GfxDevice& gfxDevice, RenderResources& resources)
{
const MaterialID rampMaterial = AddPrototypeMaterial(gfxDevice, resources, "Green", 0.6f);
const MaterialID platformMaterial = AddPrototypeMaterial(gfxDevice, resources, "Purple", 0.5f);
constexpr float laneZ = 2.0f;
constexpr float platformHeight = 1.0f;
constexpr float rampStartX = 9.0f;
constexpr float rampLength = 3.0f;
constexpr float rampThickness = 0.3f;
constexpr float travelDistance = 8.0f;
const glm::vec3 platformSize{3.0f, 0.3f, 3.0f};
const float platformTop = GroundHeight + platformHeight;
const glm::quat rampRotation =
glm::angleAxis(std::atan2(platformHeight, rampLength), glm::vec3{0.0f, 0.0f, 1.0f});
const glm::vec3 rampTopCenter{rampStartX + rampLength * 0.5f, GroundHeight + platformHeight * 0.5f, laneZ};
const glm::vec3 rampCenter = rampTopCenter - rampRotation * glm::vec3{0.0f, rampThickness * 0.5f, 0.0f};
const float rampSlopeLength = glm::length(glm::vec2{rampLength, platformHeight});
CreateBox(scene, gfxDevice, resources, "PlatformRamp", rampCenter,
{rampSlopeLength, rampThickness, platformSize.z}, rampMaterial, RigidbodyType::Static,
rampRotation);
const float platformStartX = rampStartX + rampLength + platformSize.x * 0.5f;
GameObject* platform = CreateBox(scene, gfxDevice, resources, "MovingPlatform",
{platformStartX, platformTop - platformSize.y * 0.5f, laneZ},
platformSize, platformMaterial, RigidbodyType::Kinematic);
platform->AddComponent<MovingPlatform>()->SetTravelOffset({travelDistance, 0.0f, 0.0f});
const float landingStartX = platformStartX + travelDistance + platformSize.x * 0.5f;
CreateBox(scene, gfxDevice, resources, "PlatformLanding",
{landingStartX + 1.0f, GroundHeight + platformHeight * 0.5f, laneZ},
{2.0f, platformHeight, platformSize.z}, rampMaterial, RigidbodyType::Static);
}
struct WallOpening {
float offset;
float width;
@@ -467,6 +507,7 @@ MainSceneObjects BuildMainScene(Scene& scene, GfxDevice& gfxDevice, RenderResour
const GameObject* door = CreateDoorway(scene, gfxDevice, resources);
CreateButton(scene, gfxDevice, resources, *door);
CreateHouse(scene, gfxDevice, resources);
CreateMovingPlatform(scene, gfxDevice, resources);
CreatePlayer(scene, objects);
LoadSpawnBallResources(gfxDevice, resources, objects);