Sign in to follow this  
Phillip Hamlyn

Best type of curve

Recommended Posts

Hi, I am positioned in 2D space facing a particular way. I have a destination point (and facing) which could be behind me or in any position. I'd like to describe a curve which would get me smoothly from my current position and facing until I reached the destination point facing in the determined direction (typically toward another similar point). I've tried describing my trajectory as a bezier curve but this didn't seem to work too well. Can anyone suggest a better algorithm ? Phillip

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hermite interpolation is what you need. it takes two positions and their derivatives as input. google will surely provide you with a decnet explanation, but its not that hard to derive it yourself.

one thing though: using interpolation to get from a to b has some pittfalls: its not really concerned with physical reality. say your destination is arbitrary and far away, things will look awkward if your entity translates to there in the same time as it does for a short distance.

id advocate some iterative solution for this type of problem, but youll have to decide for yourself if the above is a problem.

Share this post


Link to post
Share on other sites
Hi,

I suggest a phisical solution. Ships turn slowly because they have a maximum turning rate. So, consider a maximum turning speed per second... like 30degrees per second. Then make your ship move forward in any direction but try to turn it until its aligned with your target point. Thats all.

Luck!
Guimo

Share this post


Link to post
Share on other sites
Thanks all. Another related question ...

Having got the bezier/hermite calculation working Ok I'm loading the early and late values of 'time' in order to get better definition on the 'tightest turns'. This works to my satisfaction but in some circumstances I get 'camera shake' as I point the camera at the next sample on the curve. I thought that these curves would prove to be smooth irrespective of the sampling rate but that doesn't seem to be so.

Has anyone else found this, and is there a solution ? Currently I'm havign to ignore 'small angle changes' of the camera to compensate but it doesn't seem a good approach.

Phillip.

Share this post


Link to post
Share on other sites
Hi,

I think I have to agree with Guimo on this - unless you have some other control points (ie you have to get from A to B but also pass through C, avoiding a planet), then a feedback loop is probably the simplest way and should still get a nice effect.

Yes, you can do all sorts of curve fitting, but isn't this more bang for your buck:

if(not heading straight at target)
turn degrees equal to turning radius (unless that is too far)
move forward speed units

Slightly more elegant would be damping the turn (ie make your turn angle a decreasing function of the angle left to turn, so the turn speed decreases as you become more orientated to the target).

I think one of the recent Game Developer magazines had an article on this.

Regards,
Jim.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this