Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kazen · May 12, 2015 at 09:49 PM · physicsrigidbodypathcurvespline

Moving rigidbody along spline, and being able to use physics

Hi,

So I've been trying to make a rigidbody along a spline that I've created, but I'm stumped about how I'm supposed to do this while the rigidbody (right now, and for testing a box) should stay on the spline, while also keeping it in the physics-simulation. I've seen examples done in iTween, on this examples page, namely the "Path-constrained characters" one, and "Using PutOnPath and PointOnPath", but it seems like the objects accelerates when points have higher distances between eachother.

What I have done:


  • I can fetch points on the spline (made by a bunch of bezier curves)

  • I can fetch them by time-percentage, but also on distance, because I've done an arclength approximization, so I can get a constant speed when moving on the spline.

I think those are the vital parts for getting this to work(?). What I want to do is getting the object to move along the path, even if the speed to move along the path would be high, and I want the object to still reach to obstacles, hills and so on that I would put on the path. Anyone has good idea?

Thanks for reading (and hopefully helping =) )

Comment
Add comment · Show 3
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 Sethhalocat · May 12, 2015 at 09:52 PM -1
Share

Say wahhhhhh (In other words, im cinfused and u lost me lol)

avatar image kinyodas · Jan 15, 2016 at 05:10 PM 0
Share

I'm curious myself; I've been trying to find a similar solution and am experimenting with some code to make it happen. If I have a breakthrough, I'll let post it here.

avatar image taylank · Jan 16, 2016 at 04:10 AM 0
Share

You may want to elaborate what exactly you mean by physics-simulation. For instance when the rigidbody hits a collider along the spline, should it stop? Should it bounce back? What if the physics simulation sends the body off the spline, should it snap back to the spline? Should it transform its momentum along the direction of the spline?

If what you want is something along the lines of rigidbody constraints but on a variable axis (i.e. spline), I'd suggest simulating the velocity.

So for a given fixedupdate with rigidbody.velocity, the distance traveled will be rigidbody.velocity.magnitude * Time.fixedDeltaTime. Add that distance to the current position on the spline and figure out the resulting position, which is where you should move the rigidbody to with rigidbody.$$anonymous$$ovePosition

You'll need extra code to figure out the direction like when you actually want the body to go back along the spline in reaction to a collision.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Jan 16, 2016 at 03:35 PM

As taylank said, calculate either the next position the rigidbody should go and move it there with MovePosition, or calculate the velocity towards that point and set its velocity. Either way, do this in FixedUpdate(), that will keep all changes in the physics timestep and it will work physically. Notice that deltaTime IS fixedDeltaTime in the FixedUpdate loop by default, so no need to use fixedDeltaTime there.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to shot a soccer ball in curve path according to the swipe type 2 Answers

Constrain rigidbody movement to spline at high speeds / sharp curves 3 Answers

Add force along a path 1 Answer

Smoothing a path 1 Answer

-Accurate- following of a Bézier curve 0 Answers


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