How would I offset this Satellite's angle?

[Post note after solution]: every time I mention “offset angle” in here, what I mean in terms of an actual satellite is their inclination angle. Didn’t know that’s what it was called until I researched a little.

I have a satellite that can revolve around a planet on it’s X and Z axes. That code works fine, here is a dumbed down version of what that looks like:

local circle = 2*math.pi
local sin = math.sin
local cos = math.cos

local radius = 5
local origin = Vector3.new(0,10,0) -- example, origin in my code is the Planet's position

for i = 0, circle, circle/120 do
    local offset = Vector3.new(cos(i), 0, sin(i)) * radius
    satellite.CFrame = CFrame.new(origin + offset, origin)
    task.wait()
end

Here’s what my regular X, Z revolving satellite looks like:
https://gyazo.com/01afb6247fb1beda8293a9a3cb140a62

If you follow the path that the satellite takes and draw it (red line), what I want to achieve is to be able to ‘tilt’ it on that Y axis (like the blue line shows).

I assume somewhere in this math there should be a * CFrame.Angles(0, offsetAngle, 0), but I’ve tried various spots and it doesn’t seem to work. Alternatively, I’ve tried just doing sin(math.rad(offsetAngle)) for the Y component of the Vector3, but that doesn’t get me the result I’m looking for.

Bonus points to anyone who can solve it and explain why their solution works.

So you can do this here;
local offset = Vector3.new(cos(i), sin(os.clock()) * radius, sin(i)) * radius`

That led me to get this odd result:

https://gyazo.com/eec84b65b7b34e72d9e9762a2690b2e6

But not quite what I was looking for. I need some code that involves the offsetAngle to just tilt the entire path that the satellite takes.

Can you show me what you want? :smiley: do you have like any footage

image

This red line here is the path I’m trying to get my satellite to follow (given an offsetAngle). Instead of just going around the X, Z axes.

I thought about the problem a little harder, even drawing unit circles on the X,Y, X,Z and X,Y,Z planes and realized why my attempt of doing sin(math.rad(offsetAngle)) was giving me the result it was. As i approached the distance of a circle (in radians), the Y position was static because I wasn’t involving i at all in the Y positions calculation.

The solution (at least seems to be): sin(i) * sin(rad(offsetAngle)) which makes sense in hindsight. sin(i) is just giving you the Y value of the path at any point (between -1 and 1). But if I didn’t include my offsetAngle at all, it would go all the way up. Multiplying sin(i) to sin(rad(offsetAngle)) gives you the Y value and sort of clamps it, if that’s the correct way to describe it.

Example of it working:
https://gyazo.com/5837528ce0a53161918f25a8f28299df

The final code (using the example code I referenced above, not the code I have in my file):

local circle = 2*math.pi
local sin = math.sin
local cos = math.cos
local rad = math.rad

local offsetAngle = 15
local radius = 5
local origin = Vector3.new(0,10,0) -- example, origin in my code is the Planet's position

for i = 0, circle, circle/120 do
    local offset = Vector3.new(cos(i), sin(i) * sin(rad(offsetAngle)), sin(i)) * radius
    satellite.CFrame = CFrame.new(origin + offset, origin)
    task.wait()
end
1 Like