Part rotating in weird way

The script I made for creating a wave and tweentping it in front of a player doesnt work as intented I want it to dont rotate in any direction besides Y when setting the start position but yet it does rotate in diffrent ways


I’ve tried using math.rad, setting X and Z to 0

game.ReplicatedStorage.wave.OnServerEvent:Connect(function(player)
	local wavd = game.ReplicatedStorage.wavd:Clone()
	local dpos = player.Character:FindFirstChildOfClass("Tool").Handle.Position
	local dpoos = player.Character:FindFirstChildOfClass("Tool").Handle.Rotation
	local tweenservice = game:GetService("TweenService")
	wavd.Parent = workspace
	wavd.Position = dpos
	wavd.Rotation = Vector3.new(dpoos.X, dpoos.Y + 180, dpoos.Z)
	wavd.Anchored = true
	wavd.CanCollide = false
	wait()
	local e = player.Character:WaitForChild("HumanoidRootPart").CFrame.LookVector
	local endpos = player.Character:WaitForChild("HumanoidRootPart").Position + e * 50
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear, 
		Enum.EasingDirection.Out, 
		0, 
		false, 
		0
	)
	tweenservice:Create(wavd, tweenInfo, {CFrame = CFrame.new(endpos) * wavd.CFrame.Rotation}):Play()
end)
5 Likes

Try using CFrames instead of rotation and position, and character’s CFrame instead of the tool, as it would be easier to uderstand and implement

2 Likes

It almost looks like you are running into what’s called Gimbal lock. CFrame orientation causes issues when you rotate an object so its angles are multiples of 90 degrees. This is because if you rotate something on one axis the other 2 axes now align and will mess each other up.

Search for ‘gimbal lock’ in the forums. They explain it better than I can and have Solutions to the issue.

2 Likes

wavd.Rotation = Vector3.new(wavd.Rotation.X,dpoos.Y + wavd.Rotation.Y, wavd.Rotation.Z)
Will that work if I set wavd rotation to 0,180,0?

1 Like

I don’t know a whole lot about it, I’ve just read those posts and know that this could be an issue. Have a look at the way the other posts were Solved.

I was just wondering if it’s possible to make seperate euler angle that will only have y value is it possible?

Not sure.
I’ve seen comments about not CFraming using XYZ and using YXZ (or something like that, I don’t recall exactly) or also using Quaternions to get rid of it entirely. Rotate objects with QUATERNIONS | Definitive guide
I barely understand the theory behind it, but how to get it to work is beyond me…