Need help tweening with CFrames

I am trying to make an attack that shoots spikes out in all directions

everytime i try tweening the spikes in the direction they’re pointing at they just stand in place and face upwards

I have tried to use different vectors like up and right but i havent found any success yet

for info the orientation indicator shows up on the side of the spike

here is my code i have no idea what went wrong here

		local Spike = script.Spike:Clone()
		Spike.Orientation = Vector3.new(0, Degrees * i, 90)
		Spike.Position = IcyModel.PrimaryPart.Position - Vector3.new(0, 2, 0)
		Spike.Parent = workspace
		
		local SpikeInfo = TweenInfo.new(
			1
		)
		
		local SpikeGoal = {
			CFrame = Spike.CFrame * Spike.CFrame.LookVector * 5
		}
		
		local SpikeTween = TweenService:Create(Spike, SpikeInfo, Goal)
		SpikeTween:Play()

You gotta add the look vector instead of multiplying it. Also you are not supplying the goal params to :Create (ie. you are giving “Goal” instead of “SpikeGoal”); is that a mistake?

1 Like

Im sure the problem is here:

local SpikeGoal = {
			CFrame = Spike.CFrame * Spike.CFrame.LookVector * 5
		}

Could you try this and let me know what you got?

local SpikeGoal = {
        CFrame = Spike.CFrame * CFrame.new(0, 0, -5)
    }

Also noticed that you added a variable called SpikeGoal, but inside the Tween Parameters You Said Goal.

It’s because you’re using Spike.CFrame * Spike.CFrame.LookVector * 5,
That does not calculate end position Instead use spike’s orientation to determine it’s direction

local Spike = script.Spike:Clone()
Spike.Orientation = Vector3.new(0, Degrees * i, 90)
Spike.Position = IcyModel.PrimaryPart.Position - Vector3.new(0, 2, 0)
Spike.Parent = workspace

local SpikeInfo = TweenInfo.new(1)

local angle = math.rad(Degrees * i)
local direction = Vector3.new(math.cos(angle), 0, math.sin(angle))

local goalPosition = Spike.Position + direction * 20 -- Your Distance Here

local SpikeGoal = {
    CFrame = CFrame.new(goalPosition, goalPosition + direction)
}

local SpikeTween = TweenService:Create(Spike, SpikeInfo, SpikeGoal)
SpikeTween:Play()

Thanks for pointing out that i used the wrong params and wrong symbols i seem to have missed that because i assumed my math was wrong (it was thanks to mythical for correcting me really appreciate it)

so in short thanks to all of you for helping

Question; why are you using trigo functions here to attain the direction?

local direction = Vector3.new(math.cos(angle), 0, math.sin(angle))

cos and sin are used here because they’re efficient way to convert an angle into a 2d direction vector

cos angle gives the x and sin angle will give you z of anunit vector on a circle that way we will create a direction vector that points outward from the center at the specified angle which is what we need for a spike around point

Imaging standing in a round room Pointing
cos(angle) would be left and right movement
sin angle would be forward/backward movement
This lets you accurately point to any spot on the room wall

Hope This Help

Oh that’s some advanced stuff. Thanks for the clarification

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.