Hello, i am pretty new to jogl and i would like to know if theres a chance to move an object along a given path. i already know how to rotate and how to move it straight forward but now i want to try it with a curve, but i have no idea how it works. Could anyone give me a hint ?
thanks in advance
If you already have code that defines a path, like a (part of a) circle, a sine-wave or whatever, wrapped in a function that takes the ‘travelDistance’ argument, and it returns the coordinates, you’d only need to call the function twice with a very small difference in ‘travelDistance’. Now you have two coordinates, from which you can calculate the heading of your object, using Math.atan2(y, x)
i just completed a project where i had particles that needed to follow a curve through space. i defined a bezier curve, and then stored positions in my particles relative to that curve. so a particle might be at .5, .25, 2PI radians. this translates to t = .5 ( the distance along the bezier curve from 0, 1 ), .25 is distance along a normal ray of MAX_RAY_LENGTH, also in the 0,1 parameter space using linear interpolation, and 2PI radians is the amount of rotation around the curve at t = .5.
using this setup, i was able to perform collision, and add rules for the particles behavior and let it run. the particles then appear to follow an invisible path through space. this could be extended to any object. however, this is good for sprites and particles only.