GUI objects are automatically repositioned when they are scaled. To achieve the desired effect, you will need to tween BOTH Size and Position.
There are few considerations:
- Frame AnchorPoint should be set at 0.5,0.5. This is to ensure Your frame moves properly.
- Both frame initial and final Position and Size should only use scaling and not pixel offset. This is to ensure effect looks the same on all screen sizes.
- To properly calculate the object final position, since the frame is rotated, you will have to use mathemiatical sine and cosine function (
math.sin()
, `math.cos()), that you need to multiply final Position with. You may also use trial and error (as I did), but then you cannot have random slashes on screen. Finding a proper formula is not something I am very good at, but it is possible.
- Finally, rotated frames behave weird, consider other solution. Fullscreen ViewPortFrame with 3D objects just in front of camera will look really nice imho.
Now for the solution:
--initial settings, feel free to set them in explorer instead
object.AnchorPoint = Vector2.new(0.5,0.5)
object.Size = UDim2.new(0.001,0,0,0)
object.Position = UDim2.new(0.2,0,0,0)
local targetSize = UDim2.new(0.001,0,1.5,0)
local targetPosition = UDim2.new(0.03,0,0.5,0) -- that was trial end error approach
--local targetSize = UDim2.new(0, 3,1, 10)
local tweenInfo = TweenInfo.new(.5)
local tween = TweenService:Create(object, tweenInfo, {Size = targetSize, Position = targetPosition})
tween:Play()
EDIT: It seems that the final position will also depend on the screen aspect ratio, so there’s that.
I have found an alternative solution. Simply resize the frame both ways, while keeping it in the same spot. True, the frame will resize outside of the screen, but the player won’t notice the difference anyway. Just make sure Anchor point is at 0.5, 0.5.
object.AnchorPoint = Vector2.new(0.5,0.5)
object.Size = UDim2.new(0.001,0,0,0)
local targetSize = UDim2.new(0.001,0,1.5,0)
local tweenInfo = TweenInfo.new(.5)
local tween = TweenService:Create(object, tweenInfo, {Size = targetSize})
tween:Play()