C-Dawg
10-16-2006, 01:24 PM
I'm seeking some help on how I'd use ZScript to change the orbit of a spinning body. Essentially, I'm looking to re-create the ball-and-chain spinning enemies from LttP. This would consist of a minimum of 2 FFCs: the Knight and his Mace. It could have three or for more FFCs to act as the chain, but they can be added easily once the underlying function is defined.
The orbit is no problem. I came up with some functions based on the cartesian definition of a circle (x^2 + y^2 = radius), and DarkDragon's demo has a much more elegant orbit algorithim using the sin function. Same with following Link; I came up with a nested if situation involving comparing Link's position to the FFC, and his more elegantly uses the distance formula.
The problem is what happens when the Knight strikes out at Link. The FFC can't just zip straight to Link's position; it has to swing outwards in a natural looking attack influenced by it's orbit.
I have a few ideas on how to do this, but I havn't done trig in so long that I'm convinced some of you can make the algorithim more efficent. My suggestion would be to trigger an attack every five or six spins of the mace. Once the attack is triggered, the mace continues to orbit, but the tangent line to it's orbit is calculated each tic. Once Link is sufficently close to the tangent line extending in the same direction as the Mace's movement, his position at that tic is grabbed. Then, the mace's orbit is modified by moving it closer to link's grabbed position for a few tics, then back to the orbit. Then the trigger is cleared and the mace waits for another attack. Essentially, this would result in the mace continuing it's orbit but swinging out towards Link's position every few revolutions.
Any ideas to tighten this up?
The orbit is no problem. I came up with some functions based on the cartesian definition of a circle (x^2 + y^2 = radius), and DarkDragon's demo has a much more elegant orbit algorithim using the sin function. Same with following Link; I came up with a nested if situation involving comparing Link's position to the FFC, and his more elegantly uses the distance formula.
The problem is what happens when the Knight strikes out at Link. The FFC can't just zip straight to Link's position; it has to swing outwards in a natural looking attack influenced by it's orbit.
I have a few ideas on how to do this, but I havn't done trig in so long that I'm convinced some of you can make the algorithim more efficent. My suggestion would be to trigger an attack every five or six spins of the mace. Once the attack is triggered, the mace continues to orbit, but the tangent line to it's orbit is calculated each tic. Once Link is sufficently close to the tangent line extending in the same direction as the Mace's movement, his position at that tic is grabbed. Then, the mace's orbit is modified by moving it closer to link's grabbed position for a few tics, then back to the orbit. Then the trigger is cleared and the mace waits for another attack. Essentially, this would result in the mace continuing it's orbit but swinging out towards Link's position every few revolutions.
Any ideas to tighten this up?