Fix parallel universes, truncate ceiling raycasts.

This commit is contained in:
Max 2023-07-12 01:11:34 -05:00
parent 9d11bcebf9
commit 0e76b4f551
2 changed files with 42 additions and 15 deletions

View file

@ -13,6 +13,9 @@ rayParams.IgnoreWater = true
local SHORT_TO_RAD = (2 * math.pi) / 0x10000
local VECTOR3_XZ = Vector3.one - Vector3.yAxis
local TweenService = game:GetService("TweenService")
local fadeOut = TweenInfo.new(0.5)
local CARDINAL = {
-Vector3.xAxis,
-Vector3.zAxis,
@ -69,7 +72,7 @@ end
function Util.Raycast(pos: Vector3, dir: Vector3, maybeParams: RaycastParams?, worldRoot: WorldRoot?): RaycastResult?
local root = worldRoot or workspace
local params = maybeParams or rayParams
local result: RaycastResult? = root:Raycast(pos, dir, params)
local result = root:Raycast(pos, dir, params)
if script:GetAttribute("Debug") then
local color = Color3.new(result and 0 or 1, result and 1 or 0, 0)
@ -82,7 +85,12 @@ function Util.Raycast(pos: Vector3, dir: Vector3, maybeParams: RaycastParams?, w
line.Adornee = workspace.Terrain
line.Parent = workspace.Terrain
task.delay(2, line.Destroy, line)
local tween = TweenService:Create(line, fadeOut, {
Transparency = 1,
})
tween:Play()
task.delay(fadeOut.Time, line.Destroy, line)
end
return result
@ -128,22 +136,36 @@ function Util.FindFloor(pos: Vector3): (number, RaycastResult?)
if result then
height = Util.SignedShort(result.Position.Y)
result.Position = Vector3.new(pos.X, height, pos.Z)
return height, result
else
return height, nil
end
return height, result
end
function Util.FindCeil(pos: Vector3, height: number?): (number, RaycastResult?)
local newHeight = 10000
if Core:GetAttribute("TruncateBounds") then
local trunc = Vector3int16.new(pos.X, pos.Y, pos.Z)
if math.abs(trunc.X) >= 0x2000 then
return newHeight, nil
end
if math.abs(trunc.Z) >= 0x2000 then
return newHeight, nil
end
pos = Vector3.new(trunc.X, trunc.Y, trunc.Z)
end
local head = Vector3.new(pos.X, (height or pos.Y) + 80, pos.Z)
local result = Util.RaycastSM64(head, Vector3.yAxis * 10000)
if result then
return result.Position.Y, result
else
return 10000, nil
newHeight = result.Position.Y
end
return newHeight, result
end
function Util.FindWallCollisions(pos: Vector3, offset: number, radius: number): (Vector3, RaycastResult?)

View file

@ -461,19 +461,24 @@ local function update()
local now = os.clock()
local gfxRot = CFrame.identity
-- stylua: ignore
local scale = character:GetScale()
Util.Scale = scale / 24 -- HACK! Should this be instanced?
Util.Scale = scale / 20 -- HACK! Should this be instanced?
-- Disabled for now because this causes parallel universes to break.
-- TODO: Find a better way to do two-way syncing between these values.
--[[
local pos = character:GetPivot().Position
local dist = (Util.ToRoblox(mario.Position) - pos).Magnitude
local humanoid = character:FindFirstChildOfClass("Humanoid")
if dist > (scale * 20) then
if dist > (scale * 20) then
mario.Position = Util.ToSM64(pos)
end
]]
local humanoid = character:FindFirstChildOfClass("Humanoid")
local simSpeed = tonumber(character:GetAttribute("TimeScale") or nil) or 1
subframe += (now - lastUpdate) * (STEP_RATE * simSpeed)
lastUpdate = now