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
2
Question by stefan_ · Aug 19, 2014 at 01:05 PM · velocitybeginner

Why does my sphere object stop moving on collision?

Hi,

what a refreshingly busy site! I'm a new unity user working my way through one tutorial after the other.

In my experimental unity scene i have a sphere that's supposed to be bouncing between two caps infinitely (see picture). The sphere's speed is adjustable in the editor (default: 1) by a public speed-variable in the controlling script. As I increase speed to a value of round 3 or 4 the sphere still bounces in between the caps a couple of times (how many time differs everytime) and then stops on collision with one of the caps, velocity being 0 at this point.

code:

 public var speed : float;
 
 function Start(){
     speed = 1;
     rigidbody.velocity.y = speed;
 }
 
 function Update () {    
     Debug.Log(rigidbody.velocity.y);
 }
 
 function OnCollisionEnter(collision : Collision) {    
     
     Debug.Log(rigidbody.velocity.y);
 
     if(rigidbody.velocity.y > 0){
         rigidbody.velocity.y = -speed;
     }else{
         rigidbody.velocity.y = speed;    
     }
 }

What is it that I'm not considering?

scene:

alt text

sphere_bouncing.jpg (15.7 kB)
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

1 Reply

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

Answer by Scribe · Aug 19, 2014 at 01:12 PM

Does the same happen if you change the caps to triggers (check the Is Trigger box of their colliders) and change your code to use OnTriggerEnter(other : Collider)?

I believe the issue is probably that OnCollisionEnter means the ball has collided, and if it has collided then it's speed will be being changed, it will therefore be quite likely that at the time of collision the speed is set to 0 and therefore rigidbody.velocity.y = speed; will be called, even if that is not actually the correct direction!

Comment
Add comment · Show 2 · 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 stefan_ · Aug 19, 2014 at 06:06 PM 0
Share

thanks Scribe. it actually works with OnTriggerEnter(other : Collider) i.e. the sphere no longer stops. Your explanation sounds plausible but I don't see why it always worked correctly for a couple of bounces and then failed at the 3rd to 10th time. i guess it must have something to do with the internal workings of unity.

avatar image Scribe · Aug 20, 2014 at 10:16 PM 0
Share

glad you got it working. I'm not sure why it takes 3 before it happens but it would make sense why it happens after a random number, out of interest, do you remember what your Debug.Log was printing with your old setup?

Also alt text please! It helps others find the answer and I get karma! woop :D

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I tweak acceleration and deceleration of a Rigidbody2D with .AddForce()? 0 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

relativeVelocity how to? (noob question) 2 Answers

[RESOLVED! :D][C#] Friction/Deceleration - Compiler won't let me damp individual Rigidbody axes to 0. Force in opposite direction maybe? 2 Answers

Wht isn't the sphere moving and rebounding properly? 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