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 gisli · Mar 25, 2012 at 02:38 PM · velocitygravityaddforceballbounce

Bouncing Ball Game

Hi I´m a noob in Unity and I´m trying to figure out the bounce of object such as a ball, I´m crating a small game with springboards with different bounce force. Such as Springboard1 has the bounce of 4, springboard2 has the bounce of 8 and springboard3 has the bounce of 12. The springboard has to push the player with these different kinds of forces. I´ve tried everything and the ball does gain extra force but just bounces upwards. Anyone can help I´ve tried this code but no avail.

 var snapjump : int = 8;
 var microjump : int = 2;
 var superjump : int = 13;
 
 
 function OnCollisionEnter (other : Collision) {
     if(other.gameObject.tag == "snapjump") {
               rigidbody.velocity = Vector3.up * snapjump;
         
     }
     if(other.gameObject.tag == "microjump") {
               rigidbody.velocity = Vector3.up * microjump;
     }
     if(other.gameObject.tag == "superjump") {
               rigidbody.velocity = Vector3.up * superjump;
     }
 
 }

As you can see in the screenshot the springboards are purple but with different kind of tags. alt text

Comment
Add comment · Show 2
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 AlucardJay · Mar 25, 2012 at 02:47 PM 0
Share

in the first line of the collision function , type

 print("other.gameObject.tag = " + other.gameObject.tag);

then you should be able to see the tag, if it is correct, if you have actually assigned the tags or not. Try this.

also, could you please edit your question so the script is formatted correctly ? thx.

avatar image AlucardJay · Mar 26, 2012 at 02:02 AM 0
Share

Hello @gisli , please post replies in the 'comments' area , don't post your reply as a new answer. You can add comments here and delete your 'answers'.

With the problem, your ball is probably going too fast for the collision to be detected. For example, on one frame-loop the ball is not touching the wall/springboard , but on the next frame-loop the ball has passed the wall , so the collision isn't detected .

There are 2 things to look at : raycasting from your ball , or making changes to the Time $$anonymous$$anager.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by gisli · Mar 25, 2012 at 05:31 PM

The tags are correct and the ball gets bounced correctly now with these codes

 var snapjump : int = 10;
 var microjump : int = 4;
 var superjump : int = 15;
 
 
 function OnCollisionEnter (other : Collision) {
     if(other.gameObject.tag == "microjump") {
                print("other.gameObject.tag = " + other.gameObject.tag);
                rigidbody.velocity = transform.up * rigidbody.velocity.magnitude * 1.0;
     }
     if(other.gameObject.tag == "snapjump") {
         print("other.gameObject.tag = " + other.gameObject.tag);
            rigidbody.velocity = transform.up * rigidbody.velocity.magnitude * 1.2;
     }
     if(other.gameObject.tag == "superjump") {
         print("other.gameObject.tag = " + other.gameObject.tag);
               rigidbody.velocity = transform.up * rigidbody.velocity.magnitude * 1.4;
     }
 
 }

But when the ball goes to fast it goest through the objects as you can see in the video Youtube Video

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
avatar image
0

Answer by gisli · Mar 25, 2012 at 08:55 PM

Anyhow to fix this object moving through another object ?

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
avatar image
0

Answer by gisli · Mar 25, 2012 at 08:55 PM

Here is the fixed code and it works as you can see in the video YouTube Video

 #pragma strict
 
 var microforceAmount : int = 1;
 var snapforceAmount : int = 5;
 var superforceAmount : int = 8;
 
 function OnCollisionEnter(playerCol : Collision)
 {
     if(playerCol.gameObject.tag == "microjump"){
         rigidbody.AddForce(rigidbody.velocity.normalized * microforceAmount, ForceMode.Impulse);
     }
     if(playerCol.gameObject.tag == "snapjump"){
         rigidbody.AddForce(rigidbody.velocity.normalized * snapforceAmount, ForceMode.Impulse);
     }
     if(playerCol.gameObject.tag == "superjump"){
         rigidbody.AddForce(rigidbody.velocity.normalized * superforceAmount, ForceMode.Impulse);
     }
     
 }
 
 function Update () {
 
 }
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

How to reduce bounce? 1 Answer

How to slow or stop an object with no gravity 2 Answers

Correcting Directional velocity for a plane 0 Answers

Gravitational pull without losing speed 1 Answer

Change bouncing angle with touching speed 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