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
1
Question by lemiwinks · Aug 01, 2013 at 10:19 AM · spheregolf

how can I Keep sphere attached to ground?

hey all so im making a crazy golf type game and came across another issue, when i apply power to the ball to hit it, the ball works as usual however usually hits a wall and flies up over the edge. What i want is the ball to stay on the ground at all times

Ive tried to lock the y axis keeping the ball down however the courses sometimes feauture upward/downward hills which for obvious reasons wont work as the ball is locked on the Y axis. Any ideas how i can solve this?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by sparkzbarca · Aug 01, 2013 at 02:07 PM

this allows you to have grounds of unlimited height up or down and always touch the ground.

cast a ray from ball center to the ground.

ground point = raycast.point;

cast a ray from ground point to ball center

ball point = raycast.point;

get the distance between the 2

vector3.distance(groundPoint,Ballpoint)

if the distance is greater mathf.epsilon (a really small number) then the ball isn't touching the ground.

move the ball down. Down is

-ball.transform.up

distance is what you calculate earlier

ball.transform.position = -ball.transform.up * distance;

Comment
Add comment · Show 3 · 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
avatar image lemiwinks · Aug 02, 2013 at 08:53 AM 0
Share

i see what you mean, im going to try knock out that code now. it seems perfect for what i need. thankyou. will post results =]

avatar image lemiwinks · Aug 02, 2013 at 05:03 PM 0
Share

RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit)){ //loat distanceToGround = hit.distance; print (hit.distance); }

     if (hit.distance > 0.51){
         
         //if (hit.distance > 0.5)
     
     Debug.LogWarning("your on the right track luke, keep it up =]");
     Ball.transform.position = -Ball.transform.up * hit.distance;
     }



thas what i have so far and it works to a point, ins$$anonymous$$d of snapping down it will snap down the the right of the course

avatar image lemiwinks · Aug 02, 2013 at 05:10 PM 0
Share

sorry that was a messy version, ive tidied up a bit

// Update is called once per frame void Update () {

     RaycastHit hit;
     if (Physics.Raycast(transform.position, -Vector3.up, out hit)){
       
         print (hit.distance);
     }
     
     if (hit.distance > 0.51){
         
         //if (hit.distance > 0.5)
     
     Debug.LogWarning("your on the right track luke, keep it up =]");
     Ball.transform.position = -Ball.transform.up * hit.distance;
     }
avatar image
0

Answer by wijesijp · Aug 01, 2013 at 11:01 AM

How about adding a constant downward force to the ball?

Comment
Add comment · Show 3 · 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
avatar image lemiwinks · Aug 02, 2013 at 08:23 AM 0
Share

tried this and i can get it to work however, the course assets have a physics material that gives bounce off to the ball (for the sides) and when i apply force downward the ball starts bouncing franticly lol

avatar image ArmarageX · Aug 02, 2013 at 08:40 AM 0
Share

then remove the Physics $$anonymous$$aterial ;)

avatar image lemiwinks · Aug 02, 2013 at 11:26 AM 0
Share

believe me ive tried lol, without it the ball just doesnt seem to act the way i want it to. i need that bounciness XD

avatar image
0

Answer by RPGstandard · Aug 01, 2013 at 10:31 AM

put a bound thresh hold on the ball object so it cant go beyond a certain Y coordinate.

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

20 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

Related Questions

Multiple Cars not working 1 Answer

A node in a childnode? 1 Answer

Help with city building game? 1 Answer

Gun shooting sideways. NEED HELP!!! 2 Answers

How to fire two bullets instead of one? 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