How to make an object face the direction it is moving

I want to make this spear face the direction it is moving, the direction constantly changes so I’m not sure how to go about this. I’ve tried using CFrame.Lookat but it just doesn’t seem to be working.

(https://i.gyazo.com/b4b69891c09ef748aa7339d8ae8f784e.mp4)

if straighten == false then
		local launch = script.Launch:Clone()
		launch.Parent = spear
		game:GetService("Debris"):AddItem(launch,1)
		launch:Play()
		local moving = script.Moving:Clone()
		moving.Parent = spear
		moving:Play()
		moving.Ended:Connect(function()
			local caught = script.Caught:Clone()
			caught.Parent = char.HumanoidRootPart
			game:GetService("Debris"):AddItem(caught,1)
			caught:Play()
		end)
		while straighten == false do
			local r = math.random;
			local RandomPoint = CFrame.new(r(-150,150),r(10,40),r(-50,50))
			local goal = {
				CFrame = spear.CFrame*RandomPoint
			}
			spear.CFrame = CFrame.lookAt(spear.Position,goal.CFrame.Position)
			local move = tweenService:Create(spear,TweenInfo.new(.5),goal)
			move:Play()
			straighten = true
			task.wait(.4)
			straighten = false
		end
	end

1 Like

You could try using Runservice to set the spear’s CFrame to point toward its velocity like this

game["Run Service"].Heartbeat:Connect(function()
	local Spear = workspace.Spear
	Spear.CFrame = CFrame.new(Spear.Position, Spear.Velocity)
end)

Not sure if its the best solution but when i tested it in studio it worked pretty well.

1 Like

Change the goal to a position instead of CFrame so it doesn’t take account orientation, then change it.

local RandomPoint = Vector3.new(r(-150,150),r(10,40),r(-50,50))
local goal = {
	Position = spear.Position+RandomPoint
}
spear.CFrame = CFrame.new(spear.Position,goal.Position)
local move = tweenService:Create(spear,TweenInfo.new(.5),goal)
move:Play()
1 Like

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