-
What do you want to achieve? Keep it simple and clear!
Get a part to rotate on it’s local y axis. This happens while it’s forward face is toward the sky, and it’s Orientation.Y could be any value. (“it’s forward face is toward the sky” means Orientation.X is always 90°.)
-
alternate explanation:
get a part to rotate in the same fashion that a skultulla does in LOZ OOT.
-
What is the issue? Include screenshots / videos if possible!
I really tried, and I partly figured it out. The part seems like it rotates correctly when it is aligned with the x or y axis. If it is not aligned though, the orientation breaks. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I did look, and I have been very persistent with trying to figure it out on my own, (hence the partial solution). It basically comes down to vertex transformation math.
- Side note: Because Orientation.Y could be any value, I’m fairly certain that I cannot just set orientation without vertex transformation. (I tried. It’s mentioned in the forums here.)
This script works as a server script, and is made to go into a normal part.
local RunService = game:GetService("RunService")
local foe = script.Parent
local Orientation = Vector3.new(math.rad(foe.Orientation.X),math.rad(foe.Orientation.Y),math.rad(foe.Orientation.Z))
local OrientationStart = Orientation
local OrientationStartDirection = Vector3.new(foe.Orientation.X,foe.Orientation.Y,foe.Orientation.Z)
local angle = 0
local pointToFollow = nil
-- this is a ghetto solution, but it works.
local localUp = Vector3.new(math.sin(OrientationStart.Y),0,math.cos(OrientationStart.Y))
local function lerp(a, b, t)
return (a * (1-t) + b * t)
end
RunService.PostSimulation:Connect(function(delta)
-- scales values made for 60 FPS into any FPS.
local deltaBend = 1/((1/delta)/60)
angle = angle+0.01
-- this is the hard part
local lerpValue = -(math.abs(((OrientationStartDirection.Y % 180)-90)/90)-1)
pointToFollow = foe.Position+Vector3.new(lerp(math.sin(angle),0,lerpValue),lerp(math.cos(angle),math.sin(angle),lerpValue),lerp(0,math.cos(angle),lerpValue))
-- x good pointToFollow = ActualPositon+Vector3.new(math.sin(angle),math.cos(angle),0)
-- y good pointToFollow = ActualPositon+Vector3.new(0,math.sin(angle),math.cos(angle))
foe.CFrame = CFrame.lookAt(foe.Position,pointToFollow,localUp)
end)
Edit: removed a useless function and re-named a variable contained only in notes, to it’s correct name.