Fixing an expanding beam's position

hey

So I’ve been trying to re-script a very old beam script into being a moving one instead of instant, I managed to make it move but,

https://gyazo.com/d7a003d74e035dd3a44df6b79248af55.gif

The beam always seems to be expanding from the middle.

I have tried fixing the beams position onto my right arm and adding the distance value divided by two (which in my brain would make it constantly keep one end of the beam at my arm), but it doesnt seem to work and instead flings the part completely.

for i=0,0.3,0.01 do
		wait()
		circle1.Size = circle1.Size:Lerp(Vector3.new(distance,0.2,0.2), i)
	end

This is the current loop I use in order for the beam to expand

1 Like

I recommend using a tween but the method I use is setting the position to first being at the start position then slowly starting to move it to the mid point along with the size in parallel.

Here is some quick code I have written to show how to scale the size with the position via a Tween.

local NewSize = Vector3.new(distance,0.2,0.2)--The size it will scale to.
local StartPosition = Vector3.new()--Perferably the Handle of a tool or the Hand of the player.
local TweenService = game:GetService("TweenService")
local EndPosition = Vector3.new(100, 0, 0)--Werever the player mouse hit position/Ray cast position is
local TweeningInformation = TweenInfo.new(0.3)--the 0.3 is for the required amount of time for the transition
local Tween = TweenService:Create(circle1, TweeningInformation, {--Create a new tween that scales size with position
    Size = NewSize,
    Position = StartPosition:Lerp(EndPosition, .5)--Making it half way as positions are in the center of the part.
})
circle1.Position = StartPosition
Tween:Play()--Play the tween similar in how Animations work.

Here is some doccumentation on tweening too! TweenService | Documentation - Roblox Creator Hub

2 Likes

Thank you so much, it worked perfectly!

1 Like