How Do I Achieve This Tween?

I just made the dumbest post, this is a follow up.

How would I go about tweening a parts position at the mouse position?
I have this magic system that uses a 9 point grid to create a pentagon on the floor and then fires a beam both up and downwards.
The problem is I cannot figure out a way to tween the pentagon in to a position around the cylinder, only to a fixed position.

Here’s my example:

This is how it should look:

Not looking for a free answer as I am only doing this to learn, but a step in the right direction is definitely helpful.

I would also like to get some feedback on this combat system and ways I can improve, thank you.

3 Likes

Read up on the Mouse documentation on the developer hub Mouse | Roblox Creator Documentation (you can use Mouse.Hit to get the current location)

1 Like

I use mouse properties to get the cylinder there where the cylinder is the primary part of the model. It’s more so of finding how far the pentagon lines need to be away from the cylinder and how much to tween it.

What’s your script?

30

local TS = game:GetService("TweenService")
local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
local part3 = script.Parent.Part3
local part4 = script.Parent.Part4
local part5 = script.Parent.Part5
local cylinder = script.Parent.Cylinder

local TSInfo = TweenInfo.new(
	.7,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local goal1 = {}
local goal2 = {}
local goal3 = {}
local goal4 = {}
local goal5 = {}
local goalc = {}

goal1.Position = Vector3.new(84.665, 0.025, -108.861)
goal2.Position = Vector3.new(83.189, 0.025, -108.381)
goal3.Position = Vector3.new(85.577, 0.025, -107.606)
goal4.Position = Vector3.new(83.188, 0.025, -106.83)
goal5.Position = Vector3.new(84.664, 0.025, -106.351)

goal1.Size = Vector3.new(2.244, 0.05, 0.449)
goal2.Size = Vector3.new(2.244, 0.05, 0.449)
goal3.Size = Vector3.new(2.244, 0.05, 0.449)
goal4.Size = Vector3.new(2.244, 0.05, 0.449)
goal5.Size = Vector3.new(2.244, 0.05, 0.449)

goal1.Color = Color3.fromRGB(255, 255, 255)
goal2.Color = Color3.fromRGB(255, 255, 255)
goal3.Color = Color3.fromRGB(255, 255, 255)
goal4.Color = Color3.fromRGB(255, 255, 255)
goal5.Color = Color3.fromRGB(255, 255, 255)

goalc.Size = Vector3.new(600, 2.889, 2.889)

wait(.5)

local Tween1 = TS:Create(part1, TSInfo, goal1)
local Tween2 = TS:Create(part2, TSInfo, goal2)
local Tween3 = TS:Create(part3, TSInfo, goal3)
local Tween4 = TS:Create(part4, TSInfo, goal4)
local Tween5 = TS:Create(part5, TSInfo, goal5)
local Tweenc = TS:Create(cylinder, TSInfo, goalc)

Tween1:Play()
Tween2:Play()
Tween3:Play()
Tween4:Play()
Tween5:Play()

wait(1)

cylinder.Transparency = 0.4
Tweenc:Play()

Obviously I know that the tween is set to a single position and thats why It doesnt appear around the cylinder, I was just wondering how I can get it to around the cylinder wherever the mouse was clicked.

You’ll have to do some offset calculations based on the position selected.

Is there a simple way to do that? Maybe like welds or constraints?

You can use Vector3 or CFrame operations to offset based on a given value.

How would I figure out where the pentagon parts have to be relative to the cylinder? I imagine just guessing and checking would take forever

It’s just math. I can’t exactly directly edit your script as it seems that you’re using preset positions instead of basing it off of something.

It’s a bit difficult to explain some of the math, so you can look at this script for reference:

local count = 3
local size = 1
local off = 1.2
local dis = math.pi*2*size/count
local pos = CFrame.new(0,2,0)
function gen(t)
	local o = Instance.new('Part')
	o.Name = 'Point'
	o.Anchored = true
	o.Size = Vector3.new(1,1,1)
	o.Shape = t
	return o
end
for i=0,count-1 do
	local cf = pos*CFrame.Angles(0,dis*i,0)*CFrame.new(0,0,-size*off)
	local o = gen(Enum.PartType.Block)
	o.CFrame = cf
	o.Parent = workspace
end

The purpose of this script is to generate a circle of parts around a given position, each with the same distance apart equally. Though with what you’re doing, it’s probably not exactly what you need. You could just take the position based on which ones are selected.

For offsets, it’s pretty basic. Let’s say you have a position and an offset:

local position = Vector3.new(0,1,0)
local newPosition = position + Vector3.new(-1,2,3)
print(newPosition)

Output will be:

-1, 3, 3

Now what if you want the position to offset relative to a rotated part? Well, you can use CFrame for that:

local cframe = CFrame.new(0,1,0)
local newCFrame = cframe * CFrame.new(-1,2,3)
print(newCFrame)

Output will vary depending on the orientation and all that.

This helps alot, I find references very helpful thank you

1 Like