I want to be able to rotate an object 180 degrees while it is being moved forward with a body velocity. The problem is, the object seems to be stopping while the tween goes on, and when it ends the object begins to move forward again. So I think that the tween is causing the velocity not to be able to move the object, maybe because the CFrame is being held up.
This is the code of the tween:
--gets the object's velocity and zeros it, to pause it's movement
local velo = proj:FindFirstChildWhichIsA("BodyVelocity")
velo.Velocity = Vector3.zero
--Welds to player so they can aim it
local projWeld = Instance.new("Weld",proj)
projWeld.Part0 = proj
projWeld.Part1 = humrp
projWeld.C0 = projWeld.Part0.CFrame:ToObjectSpace(projWeld.Part1.CFrame * CFrame.new(0,0,6))
--Increases size with a tween
local rotateTW = TS:Create(proj,TweenInfo.new(0.9,Enum.EasingStyle.Sine),{Size = proj.Size * 1.5}):Play()
delay(1, function()
--Removes the weld
projWeld:Destroy()
--Rotates the object 180 degrees
local rotateTW2 = TS:Create(proj,TweenInfo.new(1,Enum.EasingStyle.Linear),{CFrame = proj.CFrame * CFrame.Angles(0,math.rad(180),0)}):Play()
--Fires cilent to enable the velocity
RemoteVelo:FireClient(plr, velo)
end)
This is the code of the fire client:
RemoteVelo.OnClientEvent:Connect(function(velo)
--Sends object in direction player is facing
velo.Velocity = humrp.CFrame.LookVector * 60
velo.P = 60
end)
Hello, I think this is your problem, the problem seems to be that you’re modifying the CFrame of the part directly while a BodyVelocity object is trying to apply force to it. This might lead to some strange behavior.
Instead of directly modifying the CFrame to rotate the object, you might want to use a BodyGyro to control the rotation of the object. This way, the BodyVelocity, and BodyGyro can work together to move and rotate the object.
Here’s a modification of your code that might work:
--gets the object's velocity and zeros it, to pause it's movement
local velo = proj:FindFirstChildWhichIsA("BodyVelocity")
velo.Velocity = Vector3.zero
--Welds to player so they can aim it
local projWeld = Instance.new("Weld",proj)
projWeld.Part0 = proj
projWeld.Part1 = humrp
projWeld.C0 = projWeld.Part0.CFrame:ToObjectSpace(projWeld.Part1.CFrame * CFrame.new(0,0,6))
--Increases size with a tween
local rotateTW = TS:Create(proj,TweenInfo.new(0.9,Enum.EasingStyle.Sine),{Size = proj.Size * 1.5}):Play()
delay(1, function()
--Removes the weld
projWeld:Destroy()
--Create a BodyGyro to rotate the object
local gyro = Instance.new("BodyGyro", proj)
gyro.CFrame = proj.CFrame * CFrame.Angles(0,math.rad(180),0)
--Fires client to enable the velocity
RemoteVelo:FireClient(plr, velo)
end)
--Fire client code:
RemoteVelo.OnClientEvent:Connect(function(velo)
--Sends object in direction player is facing
velo.Velocity = humrp.CFrame.LookVector * 60
velo.P = 60
end)
This way, the BodyGyro controls the rotation of the object, while the BodyVelocity controls the movement. Please make sure to test this code thoroughly and adjust it to your specific needs.
I hope this works for you!