- Home /

# Steering using dynamically adjusted splines/curves

Hi,

I've used Unity answers many times and it's helped me to solve many issues before. This is the first time I have posted a question and I am really hoping someone out there has some experience doing what I am trying (and failing) to do and can give me a shove in the right direction...

Basically, I am trying to model horse riding and am aiming for something fairly realistic. Horses turn in sweeping curves with substantially larger radius the faster they are traveling. I also need to project the path of the horse onto the terrain so the player can see what trajectory they are on. I have been attempting to achieve this behavior using splines (hermite and b-splines). The player moves down the spline and the curve is adjusted according to input at runtime by rotating the spline points around the player. I've almost got what I want with this approach, what I have got works on a basic level (see attached) but I am struggling with the fine control. I need to be able to adjust the arc and length of the curve depending on the speed of travel. I've tried moving all the spline points in the direction of the player object (cube for now) when decreasing speed but that just flattens out the curve moving it towards a straight line, I need to maintain the same angle of turn, as it were, but do it in a shorter distance. I'm not sure how to achieve this and am hoping someone who is better at math than I am could lend some inspiration? Alternatively I am worried I'm pursuing the wrong solution in using splines and that there is a better way of achieving this sort of behavior. Anyone out there had any experience with something similar to this willing to share some insight/ideas?

Any help much appreciated.

Hi, I would try "steering behaviors", there are lots of examples & documentations on the net about this. It should be quick & easy to try and see if it's the kind of behavior you want.

I sounds almost like you want somthing similar to parabolic trajectories. I would compute it, in a similar fashion: In any given frame you allow the rider to accelerate (increase velocity) "sideways" some constant amount, regardless of the riders forward speed. (then turn the horse to face it's new "forward").

I think this will have the effect you are looking for. enabling a slow moving rider to turn in a tight curve (because side motion per frame is close to the amount of forward movement per frame). If the rider is moving fast, the curve will need to be large, because the side motion per frame is SMALL, relative to forward motion per frame.

Of course this method does NOT have the advantage the splines do, of knowing what points lie on the path, without additional computations. Rather, you would need to compute the trajectory, which requires certain assumptions, like the speed of the rider.

I tried to add a comment but it went to moderation and now seems to have vanished so I will try again...

Thanks for the responses. I have researched steering behaviours but have yet to find anything that fits my requirements. I did start off with a solution similar to @Glurth's but it wasn't ideal for a few reasons. I might try again and try precomputing a certain length forward based on current input (speed, turn amount) and draw a line based on that data. Input will fluctuate a lot and the predicted trajectory needs to be completely accurate however. I do feel like there is a solution not too far away using a spline but I lack the grasp of 3D vector maths required to find it. If I could take a straight spline and move the spline points in a way that it deformed into a circle like the two splines in the attached image I would be almost there, I would then need to decrease the radius of the turn then it would be perfect.

Ok, I'll insist a little about steering behaviors because I think that's exactly what you need :-) Steering behaviors result in nice curves that look like splines, and it's often used to simulate animal trajectories.

Basic steering is explained here: It it the same kind of computations that @Glurth describes. The object has a velocity vector = a direction vector who's length increase with the speed of the object. Then, at each computation step, this vector is added a smaller vector that will modify it's direction and/or length. This second vector is determined by the input = is the player trying to go left or right.

The spline is then drawn by repeating this process over time (or pre-computed). Example: to compute next position, the math are: newVelocity = velocity + inputVector*deltaTime; then: nextPos = pos + newVelocity * deltaTime; You can pre-compute this formula in a "for" loop using Time.fixedDeltaTime as delta time value. All those positions can be used to draw lines that will look like a spline and be the exact trajectory that the object will follow (assuming that the input does not change direction and that the real-time computations are made during FixedUpdate()).

**Answer** by parseymcparseface
·
Jun 13, 2016 at 08:47 PM

For anyone interested. I got this working perfectly without the spline. Thanks to @*dns* and @Glurth for the help. I followed the steps here and adjusted maximum force and mass vectors to get the steering behaviour how I wanted it. After that it was really easy to precompute the path as described by dns using Time.fixedDeltaTime to iterate through future positions!

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Multiple Cars not working 1 Answer

How to get lateral normals of a bezier curve 1 Answer

How to make objects running by Curve？ 0 Answers

How can I define two-dimensional curves? (like: circle) 1 Answer

Keep object on rail? 1 Answer