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 /
This question was closed Apr 13, 2016 at 06:00 PM by Toolk for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Toolk · Apr 12, 2016 at 03:52 PM · c#2d2d-physics

Debug a rigidbody2d velocity on an exact point

Hi! I'm trying to debug the velocity just on the impact on a collider(Wall) coming from a Rigidbody2D This object is a square and there is no rotation on it only movement on the X and Y axis I made this simple script but it doesn't give me any feedback on the Console Any idea why? (I can already feel how easy is the solution and wrong the script is T-T)

 using UnityEngine;
 using System.Collections;
 
 public class InfoHolder : MonoBehaviour {
 
     public GameObject ball;
 
     void OnCollisionEnter(Collision collision){
         if(collision.gameObject == ball){
             Debug.Log (ball.GetComponent<Rigidbody2D>().velocity);
         }
 
     }
 }
 


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

  • Sort: 
avatar image
2
Best Answer

Answer by MelvMay · Apr 13, 2016 at 07:22 AM

For starters, you're using the 3D collision callback 'OnCollisionEnter'. You need to use the 2D callback 'OnCollisionEnter2D' if you're using 2D physics. Note this uses 'Collision2D'.

Also, I can only presume you've assigned something to the 'ball' field otherwise it'll always be NULL which you'll never get.

Finally, you could also make it much simpler by having a field of Rigidbody2D which is passed into the callback so you don't have to search for a component which is just wasting precious cycles like so:

  using UnityEngine;
  using System.Collections;
  
  public class InfoHolder : MonoBehaviour {
  
      public Rigidbody2D ball;
  
      void OnCollisionEnter(Collision collision){
          if(collision.rigidbody == ball){
              Debug.Log (rigidbody.velocity);
          }
      }
  }


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 Toolk · Apr 13, 2016 at 05:52 PM 0
Share

Very good answer $$anonymous$$elv! But even better was how you give me the answer! (y) A lot of people around here have turn to be real idiots when they talk with Noobs like me! Thanks! =)

avatar image MelvMay ♦♦ Toolk · Apr 13, 2016 at 06:43 PM 0
Share

Np, we've all got to start somewhere. :)

Good luck.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer

Jumping from special jump orb 1 Answer

Unity 2018 2D Character Jump Glitch 1 Answer

The player randomly freezes in place while other objects move ingame 1 Answer

Multiple Cars not working 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