Skip to content

Commit

Permalink
CHange Transform to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Aug 21, 2024
1 parent f220b95 commit dcfa34d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/src/ReplicatedStorage/std/components.luau
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local components: {
Model: Entity<Model>,
Player: Entity,
Target: Entity,
Transform: Entity<CFrame>,
Transform: Entity<{ old: CFrame, new: CFrame }>,
Velocity: Entity<number>,
} = {
Character = world:component(),
Expand Down
5 changes: 3 additions & 2 deletions demo/src/ServerScriptService/systems/mobsMove.luau
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ local function mobsMove(dt: number)
table.insert(targets, (character.PrimaryPart :: Part).Position)
end

for mob, cf, v in world:query(Transform, Velocity):with(Mob):iter() do
for mob, transform, v in world:query(Transform, Velocity):with(Mob):iter() do
local cf = transform.new
local p = cf.Position

local target
Expand All @@ -42,7 +43,7 @@ local function mobsMove(dt: number)
end

local moving = CFrame.new(p + (target - p).Unit * dt * v)
world:set(mob, Transform, moving)
transform.new = moving
blink.UpdateTransform.FireAll(mob, moving)
end
end
Expand Down
2 changes: 1 addition & 1 deletion demo/src/ServerScriptService/systems/spawnMobs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local function spawnMobs()

local id = ref()
:set(Velocity, v)
:set(Transform, cf)
:set(Transform, { new = cf })
:add(Mob)
.id()

Expand Down
8 changes: 6 additions & 2 deletions demo/src/StarterPlayer/StarterPlayerScripts/systems/move.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ local Model = cts.Model
local Transform = cts.Transform

local function move(dt: number)
for _, cf, model in world:query(Transform, Model) do
model.PrimaryPart.CFrame = cf
for _, transform, model in world:query(Transform, Model):iter() do
local cf = transform.new
if cf ~= transform.old then
model.PrimaryPart.CFrame = cf
transform.old = cf
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local function syncMobs()
model.Parent = workspace

ref("server-"..id)
:set(cts.Transform, cf)
:set(cts.Transform, { new = cf, old = cf })
:set(cts.Velocity, vel)
:set(cts.Model, model)
:add(cts.Mob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ local cts = std.components

local function syncTransforms()
for _, id, cf in blink.UpdateTransform.Iter() do
ref("server-"..id)
:set(cts.Transform, cf)
local e = ref("server-"..id)
local transform = e:get(cts.Transform)
if not transform then
continue
end
transform.new = cf
end
end

Expand Down

0 comments on commit dcfa34d

Please sign in to comment.