-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b733df
commit 8f37b3e
Showing
6 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = <BasePart[]>( | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/StarterPlayer/StarterPlayerScripts/components/ColorFade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |