Ive made this effect but the problem is when I rotate the object the rotate effect rotates the other way please tell me how to fix this or even make it better.
Script:
local Functions = {}
Functions["MoveTween"] = function(Part, Position, Rotation)
local XDifferance = Part.Position.X - Position.X
local ZDifferance = Part.Position.Z - Position.Z
print(ZDifferance)
local Tween = game:GetService("TweenService")
local Goal = {}
Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(0))
if XDifferance > 0 then
Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(10))
elseif XDifferance < 0 then
Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(-10))
end
local MainTween = Tween:Create(Part, TweenInfo.new(0.1), Goal)
MainTween:Play()
MainTween.Completed:Wait()
local BackPos = {}
BackPos.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(0))
local BackTween = Tween:Create(Part, TweenInfo.new(0.05), BackPos)
BackTween:Play()
end
use the UnitVector from item to mouse, then convert it into an angle using some trigonometry
local AngleRotation = 5 --This is in degrees
local UnitVector = (Mouse.hit.p - Part.Position).Unit
local hyp = 1 / math.cos(AngleRotation)
local opp = math.sqrt(hyp^2 - 1)
local Goal = {}
Goal.CFrame = CFrame.new(part.Position, part.Position + UnitVector - Vector3.new(0,opp,0))
You can get rid of your if xDifference checks then, I’m a bit rusty at trigonometry so it might not be right, worth a shot though.
Thank you but on line 2 of your code local UnitVector = (Mouse.hit.p, Part.Position).Unit
it has an error saying Expected ')' (to close '(' at column 21), got ','
It should work, AngleRotation is how much you want the part to rotate by when it moves
i can make a pseudo-code version of it so you can fill it out yourself if you like
local HowMuchYouWantItToRotate = 5 --This is in degrees
local UnitVector = (Goal - StartingPoint).Unit
local hyp = 1 / math.cos(HowMuchYouWantItToRotate)
local opp = math.sqrt(hyp^2 - 1)
local Goal = {}
Goal.CFrame = CFrame.new(StartingPoint, StartingPoint + UnitVector - Vector3.new(0,opp,0))
Just change the ‘StartingPoint’ and ‘Goal’ and it should work