Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by parseymcparseface · May 27, 2016 at 12:14 PM · movementprogrammingmathcurvespline

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.

alt textalt text

untitled.png (264.4 kB)
untitled2.png (266.1 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image _dns_ · May 27, 2016 at 02:15 PM 0
Share

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.

avatar image Glurth · May 27, 2016 at 02:51 PM 1
Share

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 S$$anonymous$$ALL, 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.

avatar image parseymcparseface · Jun 08, 2016 at 01:55 PM 0
Share

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.

alt text

picb.png (118.6 kB)
avatar image _dns_ · Jun 08, 2016 at 02:45 PM 1
Share

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 deter$$anonymous$$ed 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 (assu$$anonymous$$g that the input does not change direction and that the real-time computations are made during FixedUpdate()).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to get lateral normals of a bezier curve 1 Answer

Controlling roll rotation when travelling along bezier curves 1 Answer

Same movement speed on server, despite send rate from client 1 Answer

How to stop player movement during dialog?,I don't know what i can write after "if" to stop player movement during dialog 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges