From 8f37b3eb609cb84d40456eef84cba289f21dd4f8 Mon Sep 17 00:00:00 2001 From: GreenAppers Date: Wed, 3 Jan 2024 23:48:28 -0800 Subject: [PATCH] Add some Backbox tweens --- .../ArcadeTables/Pinball1/Backbox.rbxmx | 2 +- .../Pinball1/Box/MaterializeWall.rbxmx | 2 +- .../shared/constants/tags.ts | 1 + src/ServerScriptService/buildin.ts | 57 +++++++++++++++++++ .../services/MapService.ts | 6 ++ .../components/ColorFade.ts | 24 ++++++++ 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/ServerScriptService/buildin.ts create mode 100644 src/StarterPlayer/StarterPlayerScripts/components/ColorFade.ts diff --git a/assets/ReplicatedStorage/ArcadeTables/Pinball1/Backbox.rbxmx b/assets/ReplicatedStorage/ArcadeTables/Pinball1/Backbox.rbxmx index e383c96..73788f2 100644 --- a/assets/ReplicatedStorage/ArcadeTables/Pinball1/Backbox.rbxmx +++ b/assets/ReplicatedStorage/ArcadeTables/Pinball1/Backbox.rbxmx @@ -132,7 +132,7 @@ 3.5033193 -1 - + Q29sb3JGYWRl -0.5 0.5 0 diff --git a/assets/ReplicatedStorage/ArcadeTables/Pinball1/Box/MaterializeWall.rbxmx b/assets/ReplicatedStorage/ArcadeTables/Pinball1/Box/MaterializeWall.rbxmx index d0748f2..bb36d63 100644 --- a/assets/ReplicatedStorage/ArcadeTables/Pinball1/Box/MaterializeWall.rbxmx +++ b/assets/ReplicatedStorage/ArcadeTables/Pinball1/Box/MaterializeWall.rbxmx @@ -13,7 +13,7 @@ 0 0 - 5.4889174 + 1.9554594 8.145643 131.22559 0 diff --git a/src/ReplicatedStorage/shared/constants/tags.ts b/src/ReplicatedStorage/shared/constants/tags.ts index fd3c004..901876d 100644 --- a/src/ReplicatedStorage/shared/constants/tags.ts +++ b/src/ReplicatedStorage/shared/constants/tags.ts @@ -4,6 +4,7 @@ export const BallTag = 'Ball' export const BarrierTag = 'Barrier' export const BlinkTag = 'Blink' export const BouncerTag = 'Bouncer' +export const ColorFadeTag = 'ColorFade' export const DrainTag = 'Drain' export const JoinTeamTag = 'JoinTeam' export const LavaTag = 'Lava' diff --git a/src/ServerScriptService/buildin.ts b/src/ServerScriptService/buildin.ts new file mode 100644 index 0000000..2b151fc --- /dev/null +++ b/src/ServerScriptService/buildin.ts @@ -0,0 +1,57 @@ +import { TweenService } from '@rbxts/services' +import { getDescendentsWhichAre } from 'ServerScriptService/utils' + +const BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT = 5 +const BUILDING_ANIMATION_PART_DELAY = 0.03 +const random = new Random() + +export function animateBuildingIn(buildingModel: Model, tweenInfo: TweenInfo) { + // Collect BaseParts and original properties + const parts = ( + getDescendentsWhichAre(buildingModel, 'BasePart').filter( + (x) => x.Name !== 'Baseplate', + ) + ) + const originalProperties = parts.map((x) => ({ + Transparency: x.Transparency, + CFrame: x.CFrame, + Color: x.Color, + Size: x.Size, + })) + + // Make parts invisible and randomly move them + parts.forEach((part, i) => { + part.Transparency = 1 + part.Color = Color3.fromRGB(255, 255, 255) + part.Size = new Vector3() + const positionOffset = new Vector3( + random.NextNumber(-1, 1), + random.NextNumber(-0.25, 1.75), + random.NextNumber(-1, 1), + ).mul(BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT) + const rotationOffset = CFrame.Angles( + random.NextNumber(-math.pi, math.pi), + random.NextNumber(-math.pi, math.pi), + random.NextNumber(-math.pi, math.pi), + ) + part.CFrame = part.CFrame.mul( + new CFrame(positionOffset).mul(rotationOffset), + ) + }) + + // Tween them back to their original state, one at a time + let lastTween: Tween | undefined // Return this so the caller can do animateBuildingIn(...).Wait() + parts.forEach((part, i) => { + const tween = TweenService.Create(part, tweenInfo, originalProperties[i]) + lastTween = tween + tween.Completed.Connect((playbackState) => { + // Sometimes Tweens stop before reaching their goal property. + const original = originalProperties[i] + part.Transparency = original.Transparency + part.CFrame = original.CFrame + }) + tween.Play() + wait(BUILDING_ANIMATION_PART_DELAY) + }) + return lastTween?.Completed +} diff --git a/src/ServerScriptService/services/MapService.ts b/src/ServerScriptService/services/MapService.ts index e50e529..46f1a36 100644 --- a/src/ServerScriptService/services/MapService.ts +++ b/src/ServerScriptService/services/MapService.ts @@ -10,6 +10,7 @@ import { isArcadeTableNextName, nextArcadeTableName, } from 'ReplicatedStorage/shared/state/ArcadeTablesState' +import { animateBuildingIn } from 'ServerScriptService/buildin' import { Events } from 'ServerScriptService/network' import { store } from 'ServerScriptService/store' import { getDescendentsWhichAre } from 'ServerScriptService/utils' @@ -167,6 +168,11 @@ export class MapService implements OnStart { const isNextName = isArcadeTableNextName(name) if (isNextName) game.Workspace.ArcadeTables?.[baseName]?.Destroy() Events.arcadeTableMaterialize.fire(player, name) + if (arcadeTable.Backbox) + animateBuildingIn( + arcadeTable.Backbox, + new TweenInfo(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), + )?.Wait() } } diff --git a/src/StarterPlayer/StarterPlayerScripts/components/ColorFade.ts b/src/StarterPlayer/StarterPlayerScripts/components/ColorFade.ts new file mode 100644 index 0000000..3a4e02f --- /dev/null +++ b/src/StarterPlayer/StarterPlayerScripts/components/ColorFade.ts @@ -0,0 +1,24 @@ +import { BaseComponent, Component } from '@flamework/components' +import { OnStart } from '@flamework/core' +import { TweenService } from '@rbxts/services' +import { ColorFadeTag } from 'ReplicatedStorage/shared/constants/tags' + +@Component({ tag: ColorFadeTag }) +export class ColorFadeComponent + extends BaseComponent<{}, BasePart> + implements OnStart +{ + onStart() { + const numberValue = new Instance('NumberValue') + numberValue.Changed.Connect(() => { + this.instance.Color = Color3.fromHSV(numberValue.Value, 1, 1) + }) + const tweenInfo = new TweenInfo(10, Enum.EasingStyle.Linear) + const tween = TweenService.Create(numberValue, tweenInfo, { Value: 1 }) + for (;;) { + tween.Play() + tween.Completed.Wait() + numberValue.Value = 0 + } + } +}