mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
CHange Transform to struct
This commit is contained in:
parent
f220b95d2f
commit
dcfa34df4e
6 changed files with 18 additions and 9 deletions
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -19,7 +19,7 @@ local function spawnMobs()
|
|||
|
||||
local id = ref()
|
||||
:set(Velocity, v)
|
||||
:set(Transform, cf)
|
||||
:set(Transform, { new = cf })
|
||||
:add(Mob)
|
||||
.id()
|
||||
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue