I have been struggling to find an algorithm to implement something that will make a direction oscillate within a cone constraint, in a helix-shaped fashion as in photo (it will always go back to the centre after traveling toward the boundaries of the constraint, it doesn't have to hit the max amplitude everytime). Do you know any algorithm that does this?

enter image description here

EDIT: My mind is telling me that this is somehow similar to a gravity pull but I don't know how to ensure that it always goes back to the centre.

up vote 2 down vote accepted

Using polar coordinates would do the trick. Here’s a graph of the function r=sin(2.3θ), with θ going from 0 to 2π:

equation graph

Given r and θ, you can convert back to Cartesian (x/y) coordinates with x = r cos θ and y = r sin θ. Increase θ steadily over time, add the resulting x and y offsets to your aim direction, and you should have the effect you’re after.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.