- Joined
- Jan 9, 2005
- Messages
- 2,126
I hope this is okay to post in the trigger forums since it math + code.
I'm trying to figure out a way to make a 3D orbit system but since I'm not particularly good at math, I'm wondering if anyone here can lend me a hand. In my research I found out this equation on stackoverflow:
So I tried to use that in this test:
Honestly I have no idea how the above formula is working. While this is in fact making a unit orbit another, it seems to only be able to do that in a vertical loop that can 'face' the angle the 'tilt' is set to. I think my approach is not good.
Ideally, the 3D orbit would have an orbit speed, an orbit distance, a 'facing' angle and a vertical tilt. This is how the customisation plays out in my head. I'm looking for a formula that will allow me to use those four values to obtain a 3D orbit. Basically, create a normal 2D orbit and tilt the Z axis. I'm not sure if approaching it that way is even feasible, so alternate solutions are welcome.
I'm trying to figure out a way to make a 3D orbit system but since I'm not particularly good at math, I'm wondering if anyone here can lend me a hand. In my research I found out this equation on stackoverflow:
JASS:
x = x0 + r sin(θ) cos(φ)
y = y0 + r sin(θ) sin(φ)
z = z0 + r cos(θ)
JASS:
library SphereOrbit initializer init
globals
private constant string ORB_MODEL = "Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl"
private real a = 0.
private real tilt = 60. * bj_DEGTORAD
private unit array u
endglobals
private function Clock takes nothing returns nothing
local real x
local real y
local real z
local real r = 200.
set a = a + 5. * bj_DEGTORAD
//set tilt = 5. * bj_DEGTORAD //phi
set x = 0. + r * Sin(a) * Cos(tilt)
set y = 0. + r * Sin(a) * Sin(tilt)
set z = 350. + r * Cos(a)
call SetUnitX(u[0], x)
call SetUnitY(u[0], y)
call SetUnitFlyHeight(u[0], z, 0.)
endfunction
private function init takes nothing returns nothing
local timer t = CreateTimer()
set u[0] = CreateUnit(Player(0), 'dumi', 0., 0., 270.)
call AddSpecialEffectTarget(ORB_MODEL, u[0], "origin")
call TimerStart(t, .03125, true, function Clock)
set t = null
endfunction
endlibrary
Ideally, the 3D orbit would have an orbit speed, an orbit distance, a 'facing' angle and a vertical tilt. This is how the customisation plays out in my head. I'm looking for a formula that will allow me to use those four values to obtain a 3D orbit. Basically, create a normal 2D orbit and tilt the Z axis. I'm not sure if approaching it that way is even feasible, so alternate solutions are welcome.