Stop part from wobbling when reflecting

I want to make a projectile that has the ability to bounce off of players and walls, but so far I noticed that sometimes it bugs out and either wobbles like crazy, flies off, or both. Here’s a video example:

Here’s the code that I’m using:

local VectorForce = script.Parent:WaitForChild("BodyVelocity")
local LookNormal = script.Parent.CFrame.LookVector
VectorForce.Velocity = (LookNormal * 60) + Vector3.new(0, 1941.5985, 0)

local RunService = game:GetService("RunService")
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {script.Parent}
RunService.Heartbeat:Connect(function(dT)
    script.Parent.Position = Vector3.new(script.Parent.Position.X, 3.26, script.Parent.Position.Z)
	script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X, script.Parent.Orientation.Y, script.Parent.Orientation.Z)
	local Raycast = game.Workspace:Raycast(script.Parent.Position, (script.Parent.CFrame.LookVector*script.Parent.Size.Z/2)*1.5, RayParams)
	if Raycast then
		local Normal = Raycast.Normal
		local ReflectedNormal = LookNormal - (2*LookNormal:Dot(Normal)*Normal)
		print(ReflectedNormal)
		VectorForce.Velocity = (ReflectedNormal * 60) * Vector3.new(1, 1941.5985, 1)
	end
end)

EDIT 1: Added line 10 to have one less thing on my list of problems, now the part just wobbles a whole lot

1 Like

Managed to solve it while playing around with an AlignOrientation object, for reference here’s the final result:

local VectorForce = script.Parent:WaitForChild("BodyVelocity")
local AlignOrientation = script.Parent:WaitForChild("AlignOrientation")
local LookNormal = script.Parent.CFrame.LookVector
VectorForce.Velocity = (LookNormal * 60) + Vector3.new(0, 1941.5985, 0)

local RunService = game:GetService("RunService")
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {script.Parent}
RunService.Heartbeat:Connect(function(dT)
	script.Parent.Position = Vector3.new(script.Parent.Position.X, 3.26, script.Parent.Position.Z)
	local Raycast = game.Workspace:Raycast(script.Parent.Position, (script.Parent.CFrame.LookVector*script.Parent.Size.Z/2)*1.5, RayParams)
	if Raycast then
		local Normal = Raycast.Normal
		local ReflectedNormal = LookNormal - (2 * LookNormal:Dot(Normal) * Normal)
		print(ReflectedNormal)
		script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, script.Parent.Position + ReflectedNormal)
		AlignOrientation.LookAtPosition = Vector3.new(script.Parent.Position + ReflectedNormal)
		script.Parent.Rotation = Vector3.new(script.Parent.Rotation.X, script.Parent.Rotation.Y, 90)
		VectorForce.Velocity = (ReflectedNormal * 60) * Vector3.new(1, 1941.5985, 1)
	end
end)