So like the title says i need to tween something in a certain direction, which is upwards in this case. The size does tween properly as i need it to but i have no idea how to make it go upwards only, instead of that it goes both upwards and downwards so the hand of the character which should be at the bottom of the enlarged object is actually in the middle.
Here’s the script, first tween is the one i need to go in a certain direction.
01 | wait() |
02 |
03 | |
04 |
05 | script.Parent.OnServerEvent:Connect( function (player,tool) |
06 |
07 | local sword = tool.SwordMesh |
08 |
09 | local handle = tool.Handle |
10 |
11 | local blade = tool.Blade |
12 |
13 | local weld = handle.Weld |
14 |
15 | local TweenService = game:GetService( "TweenService" ) |
16 |
17 | local TweenInform 1 = TweenInfo.new( |
18 |
19 | 1.5 , |
20 |
21 | Enum.EasingStyle.Quad, |
22 |
23 | Enum.EasingDirection.Out, |
24 |
25 | 0 , |
26 |
27 | false , |
28 |
29 | 0 |
30 |
31 | |
32 |
33 | ) |
34 |
35 | |
36 |
37 | local properties = { |
38 |
39 | Size = Vector 3. new( 56 , 75 , 9 ); |
40 |
41 | Transparency = 0 ; |
42 |
43 | |
44 |
45 | } |
46 |
47 | local Tween = TweenService:Create(sword,TweenInform 1 ,properties) |
48 |
49 | Tween:Play() |
50 |
51 | local TweenInform 3 = TweenInfo.new( |
52 |
53 | 1.5 , |
54 |
55 | Enum.EasingStyle.Quad, |
56 |
57 | Enum.EasingDirection.Out, |
58 |
59 | 0 , |
60 |
61 | false , |
62 |
63 | 0 |
64 |
65 | |
66 |
67 | ) |
68 |
69 | |
70 |
71 | local properties 3 = { |
72 |
73 | Size = Vector 3. new( 100 , 10 , 10.6 ); |
74 |
75 | Transparency = 1 ; |
76 |
77 | |
78 |
79 | } |
80 |
81 | local Tween 3 = TweenService:Create(blade,TweenInform 3 ,properties 3 ) |
82 |
83 | Tween 3 :Play() |
84 |
85 | |
86 |
87 | end ) |
tWhen you resize a Part, it will shrink its size from x(left and right), y(upwards and downwards) and z(forwards and backwards) according to what you modify.
For example, if I change the size of say Part from {1, 7, 1} to {1, 9, 1}, the difference in size is 2 studs in the y axis: up and down - 1 stud up, 1 stud down.
If we want the Part to only change size upwards, then we need to position the Part upwards by 1 again because changing the size by 2 caused our Part to go 1 stud up & down!
In code, it might look like this
1 | local myPart = workspace.Part |
2 | myPart.Size = myPart.Size + Vector 3. new( 0 , 2 , 0 ) --adding 2 studs to the Part's current size |
3 | --since i only want the Part to size upwards, we need to offset the part by Y / 2, or in our case, 1 |
4 | myPart.Position = myPart.Position + Vector 3. new( 0 , 1 , 0 ) |
For a Tweening example, it’s the same thing. It might look something like this (example from something in your code)
01 | local TweenInform 3 = TweenInfo.new( |
02 | Enum.EasingStyle.Quad, |
03 | Enum.EasingDirection.Out, |
04 | 0 , |
05 | false , |
06 | 0 |
07 | ) |
08 | local properties 3 = { |
09 | Size = blade.Size + Vector 3. new( 10 , 10 , 10 ); --here we are adding 10 studs in size in every direction |
10 | Position = blade.Position + Vector 3. new( 0 , 5 , 0 ) --we need to add an offset of Y/2, or 5 in this case, because we need to add back the blade that went downwards as discussed previously! |
11 | Transparency = 1 ; |
12 | } |
13 | local Tween 3 = TweenService:Create(blade,TweenInform 3 ,properties 3 ) |
14 | Tween 3 :Play() |
You need to add Position to properties table . If you need the part to go upwards, while growing, it would equal half of the grow difference. For example your part original size was (16,25,3) and new size is (56,75,9) difference is (40,50,6). Then you take the middle value (for moving up and down) and divide by 2. In this case 25. That is how many studs you need to move part upwards. So your properties table will look like this:
01 | local moveFactor = ( 75 - sword.Size.Y) / 2 |
02 |
03 | local properties = { |
04 |
05 | Size = Vector 3. new( 56 , 75 , 9 ); |
06 |
07 | Transparency = 0 ; |
08 |
09 | Position = sword.Position + Vector 3. new( 0 ,moveFactor, 0 ) |
10 | } |