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 /
  • Help Room /
avatar image
0
Question by gOzaru84 · Dec 13, 2018 at 10:54 AM · roll a ballfollow path

How to make a ball rolling while following a curve path made with ways point?

I've already know how to create ways point from this youtube: link video I want to make game like Rotator in Google Play Store (see this video). That ball can roll along curve path and while keep rotating. Meanwhile in the youtube video, I tried it to change the object to sphere. It seems that it cannot rotate to its forward direction. I tried to add this code below, but it doesn't follow the curve path I make. Anyone can help me?

 RigidBody().AddForce(Vector3.forward * moveSpeed, ForceMode.Impulse); //move forward automatically

  


Comment
Add comment · Show 1
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 gOzaru84 · Dec 17, 2018 at 07:17 AM 0
Share

Anyone can help me out which part I should learn for this problem?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Vega4Life · Dec 17, 2018 at 09:57 PM

Hi. This is just something I threw together really quick, but it should give you an idea of how to do it.

 using UnityEngine;
 
     // Put on the ball object and add some waypoints
     public class BallMover : MonoBehaviour
     {
         [SerializeField] GameObject[] points;
         [SerializeField] Rigidbody body;
         [SerializeField] float force = 5f;
 
         int pointIndex = -1;
         bool movementComplete;
         Vector3 heading;
 
 
         void Start()
         {
             GetNextPoint();    
         }
 
 
         void FixedUpdate()
         {
             MoveBall();
         }
 
 
         void MoveBall()
         {
             if (movementComplete == false)
             {
                 if (Vector3.Distance(points[pointIndex].transform.position, transform.position) <= 0.2f)
                 {
                     GetNextPoint();
                 }
                 else
                 {
                     body.velocity = heading * force;
                 }
             }
         }
 
 
         void GetNextPoint()
         {
             pointIndex++;
 
             if (pointIndex < points.Length)
             {
                 heading = (points[pointIndex].transform.position - transform.position).normalized;
             }
             else
             {
                 movementComplete = true;
 
                 // Stop all the things
                 body.velocity = body.angularVelocity = Vector3.zero;
             }
         }
     }


I use rigidbody.velocity in this type of situation because I want to have total control over the speed of the ball. If we use addForce(), then the speed is additive and I would need a way to keep that under control.


Just add to your ball gameObject, then place some empty gameObject waypoints. Hope it helps!


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

159 People are following this question.

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

Related Questions

Problem with Roll a Ball Physic 0 Answers

How to create a player class and make 2 instances of the player, and handle different input key for each player? 1 Answer

roll the ball collecting cubes not working help 4 Answers

Only apply force on x and z.,How to I only add force on x and z? 1 Answer

3rd person camera for Roll a Ball 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