- Home /
How do I describe the path of a boat with a curve?
Hello math wizards of the forum. I have a question regarding a somewhat special bezier curve. I am trying to describe the path of a turning ship with a bezier curve like in the game Leviathan Warships. So far I tried a normal cubic bezier curve but as you'd expect it becomes very unnatural at tight angles. I also tried the navemesh agent but it can move very unlike a boat. Anyone have an idea or a hint where to start to create a curve that describes the movement of a boat and takes its turning radius into consideration?
Answer by Pangamini · Aug 01, 2021 at 09:37 PM
How did you get an idea that a bezier curve describes a path of a physical object, with momentum and stuff? That can easily give you very unrealistic paths. I checked the video. From what I see, there's simply a circular path followed by a straight path. So try to define a turning radius of your boat, calculate the angular distance of how much you have to travel on that circle before you can move straight.
The reason I thought a modified bezier curves might be the answer is because it already simulates something like acceleration. I like your approach but I think it might run into some trouble for targets that are very close to the boat at more than 90 degrees. In the video the turning radius "collapses" for very near points. I guess I would have to factor in the boat not accelerating to maximum if it aims for a near point. I wish there were a magic formula that takes all the factors like acceleration and turning radius into consideration but that might be too optimistic. Still thanks for the idea! ^^
Well, if the turning radius is a fixed constraint, then yes, you cannot reach a point that lies within the green circle without moving forward or backwards first. Imagine a car that's reversing to make it to a parking spot. If the turning radius is not a fixed constraint, then you could just evaluate it to be small enough so that the point you are trying to reach lies on it. Bezier curve will easily give you completely unrealistic acceleration and / or trajectory
That's probably the way to do it. Assume a fixed turning radius at maximum acceleration and speed if the target is a certain distance away and if it's inside the radius you evaluate a new turning radius with a lower speed. I think I can work with that. Thanks!
I don't know the reference game, however when you look closely the path has a green segment which seems to represent the acceleration / velocity of the object. So the object most likely has a certain max acceleration and a certain turn speed. So the path it traces seems to depends on several factors of the movement mechanic. That means if the distance to the target is rather short, it does not accelerate up to it's max speed which in turn means that the turning radius will be smaller. So I'm pretty sure they just do a forward iteration / prediction of their movement mechanic. You can see that the radius changes and also the length of the green segment changes which most likely indicates an adaptive acceleration based on the distance.
So the real question is if for some reason you want to mimic this exact behaviour or do you just need "something" like that. You generally get the best results if you just use your actual movement mechanic to draw the prediction. So all you have to do is "fast forward" / integrate your movement logic into the future and sample the path on the way.
I once did something like that in a simple lunar lander clone completely written in C++. For the prediction I literally had transparent copies of the player object which were simply updated from the current state and drawn accordingly. Though this was just a debugging feature and not a game feature -.-
For example games like Peggle most likely used the same approach for their prediction and especially for the "zen shots" which adjusts your aim slightly to get the best result with that general direction. So the game simply played through all sorts of tiny variations and sees which one gives the best result.
The green path only tells you where it will go through and where it will be after 10 seconds (that's where the green path becomes darker). Maybe I should've explained what the game does a bit better and put it into the video. I don't really need this exact behaviour but I'd like to just experiment a bit with boat movement. I think you and @Panga$$anonymous$$i are absolutely right that "fast forwarding" is probably the cleanest and best way of doing it. I think @Panga$$anonymous$$i 's answer sounded scary to me because he mentioned simulation but in hindsight that is exactly what I should do. The research paper has a very simple logic for the movement and I think it shouldn't be a problem to "cast that forward".
Your answer
Follow this Question
Related Questions
How do I fix two NavMeshAgents fighting for the same position? 1 Answer
AI movement with other factors such as paths that increase walking speed 1 Answer
How to move object along Spline at constant speed? 0 Answers
iTween for Dynamically Moving Objects around a Sphere 0 Answers
NavMesh Baking Problems 0 Answers