Moving a part relative to sphere

Did you use C0 / C1? (I can’t remember the exact property for it so I might have mentioned the wrong one)

C0 sphere, C1 cube >> chars chars

I haven’t tested it myself, but tell me if this works:
How to rotate a part around a point while retaining the orientation of the part? - Help and Feedback / Scripting Support - DevForum | Roblox

not the right result. i have a script, if i can send that to you?

edit: that post shows how to keep it looking at a part while moving straight.
what im looking for is how to slerp a part.

I think I might be thinking about something different to you, is there any chance you could send an image of a diagram, or something similar?

Here is a post that describes the same thing

I compiled the last project and created something very close to what I’m aiming for. It looks like this:

local sin, cos, acos = math.sin, math.cos, math.acos
local function slerp(p0, p1, t)
	--From https://en.wikipedia.org/wiki/Slerp
	-- See "Geometric Slerp"
	local l = p0.Magnitude
	p0 = p0.Unit
	p1 = p1.Unit
	local Omega = acos(p0:Dot(p1))
	return (
		p0 * sin( (1 - t) * Omega) / sin(Omega) +
			p1 * sin( (t    ) * Omega) / sin(Omega)
	) * l
end

local steps = 10
local last_p = origin.Position
for i = 1/steps, 1, 1/steps do
	local c = game.ReplicatedStorage.Highlighter:Clone()
	local p = slerp(origin.Position, endPoint, i)
	local d = (p - last_p).Magnitude
	c.Size = Vector3.new(1, 1, d)
	c.CFrame = CFrame.new(p, last_p) * CFrame.new(0, 0, -d * 0.5)
	c.Parent = workspace.CirclePath
	last_p = p
end

The only issue is that the sphere size is predetermined. How can I solve this?

Slerp.rbxl (89.2 KB)
Game available for editing

I’ll write a script for you with ready destination variable (used a non-existing getDestination() function as an alternative), I also assume that the Sphere and Part are in workspace.

local sphere = workspace.Sphere
local part = workspace.Part

local currentPosition = part.Position
local destination = getDestination()

local sub = destination-currentPosition
local sphereRay = sphere.Size.X/2 -- make sure that your sphere has the same X, Y and Z size values

local totalFramesCount = 100

for i=1, totalFramesCount do
    local newCFrame = CFrame.lookAt((((i/totalFramesCount*sub+currentPosition)-sphere.Position).Unit*sphereRay)+spherePosition, sphere.Position)
    part.CFrame = newCFrame * sphere.CFrame
    task.wait(0.015) -- cooldown between frames
end

Tell me if something errors or it’s not working and I’ll correct myself because I wrote this on phone. It’s also not a perfect solution because the move speed will be lower at the start and the end of the path. [Not anymore] The part will also not rotate.

First edit: corrected the newPosition variable, used val.Magnitude.Unit on accident and corrected it to val.Unit.

Second edit: Used CFrame.lookAt() constructor to make the part rotate.

Third edit: The script has been updated to assign a CFrame instead of a Position. Additionally, the CFrame is now multiplied by the sphere’s CFrame, making it relative to the sphere rather than the world.

Yep that works for movement, thanks. I’d have to look into how to get rotation working as well.

1 Like

I’ve made further edits to the script, and I believe that the rotational movement should now function properly.

First error is Couldn’t convert Vector3 to CoordinateFrame

When replacing .Position with .CFrame, the unit just flies around the earth

1 Like

Okay, I’ve fixed the script. It was probably because it was relative to the world, but all I did was multiply it by the sphere’s CFrame, and now it should work without any issues.

It’s stuck facing one direction and not actually rotating relative to *its current location on the sphere.

1 Like

Can you try this script? I got some help from AI to correct it.

local sphere = workspace.Sphere
local part = workspace.Part

local currentPosition = part.Position
local destination = getDestination()

local sub = destination - currentPosition
local sphereRay = sphere.Size.X / 2

local totalFramesCount = 100

for i=1, totalFramesCount do
    local relativePos = (currentPosition - sphere.Position)
    local newCFrame = CFrame.lookAt((((i / totalFramesCount) * sub + currentPosition) - sphere.Position).Unit * sphereRay + relativePos, sphere.Position)
    part.CFrame = newCFrame * sphere.CFrame
    task.wait(0.015)
end

Troop is floating far away from the sphere into the night sky

1 Like

I tested this script on my PC now and it works:

local sphere = workspace.Sphere
local part = workspace.Part

local currentPosition = part.Position
local destination = getDestination()

local sub = destination - currentPosition
local sphereRay = sphere.Size.X / 2

local totalFramesCount = 100

for i=1, totalFramesCount do
    local newCFrame = CFrame.lookAt((((i / totalFramesCount) * sub + currentPosition) - sphere.Position).Unit * sphereRay + sphere.Position, sphere.Position)
    part.CFrame = newCFrame
    task.wait(0.015)
end

AI failed again

image
Getting this result still. Trying to make a RON-type game but in space

I would fire a raycast at the sphere from the cursor (using ScreenPointToRay) and use the RaycastResult CFrame+Normal properties, similar to how Bullet Holes function.

View below post for place file demonstrating method