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 private void · Oct 08, 2012 at 05:51 PM · collisiontriggerpositionvelocity

How to detect collision position and velocity?

Hi, I'm trying to build a brick-breaker like game, and I handle the ball - pad collision via OnTriggerEnter(), and I want to know the x-coordinate of collision with respect to the center of paddle, to aim the ball. And I want to get the pad's (rigidbody) velocity when it hits the ball. In the code below, why does the pad velocity return 0 ?

 function OnTriggerEnter(other:Collider)
 {
     if(other.rigidbody){
     V_pad=other.rigidbody.velocity;
     //Here it returns (0,0,0) , also tried other.attachedRigidbody
     }    
 
     if(other.name=="Pad"){
     rigidbody.velocity = 
 Vector3(rigidbody.velocity.x, Mathf.Abs(rigidbody.velocity.y + V_pad),0); 
 //this part executes but with V_pad.y=0
     }
 }

Thanks for any help!

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 Fattie · Oct 08, 2012 at 05:52 PM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/ContactPoint.html

http://docs.unity3d.com/Documentation/ScriptReference/Collision.html

Just FWIW .. you realise Unity will totally handle the physics for you right? It will bounce the balls around and so on.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ChariBAM · Aug 22, 2013 at 10:16 AM

Hi,

i have tried to make a brick breaker game before and i had trouble with the pad and bouncing as well. What i did, i had 3 smaller pads and put then into and empty game object and then put the movement script on the empty so they would move... i then added a bounce material onto the ball... (it was my own because the unity one dosent give you a perfect bounce. I put the dynamic friction to 0, static friction to 0. bounciness to 1, friction combine to minimum and bounce combine to maximum... everything else was set to 0). i left the middle paddle empty of scripts but i added a box collider. i did the same with the other 2 but i added a script to make it bouce away from the pad with the OnCollisionEnter function and i added a Ball tag to the ball.

probably not what your looking for but this is how i did it

Comment
Add comment · Show 1 · 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 private void · Aug 28, 2013 at 11:09 PM 0
Share

Nice Idea, better than what I'm doing, messing with a sphere collider, but non-sphere pad :)

avatar image
0

Answer by zalan23677632 · Jan 22, 2014 at 06:49 PM

Hi there,

I was just searching the internet for something for my own brick-breaker game and I saw your question. I remember that back when I was starting my project, this was the first big challange and I finally found it. :)

Here is the code in CSHARP but you can try it in javascript also:

 void OnCollisionEnter (Collision col) {
     foreach (ContactPoint contact in col.contacts) {
         if(contact.thisCollider == collider) {
             float english = contact.point.x - transform.position.x;
             contact.otherCollider.rigidbody.AddForce(300f * english, 0, 0);
         }
     }
 }

You may need to tweak the code above and play around with the numbers but it should work if your ball is physics powered (which I guess it is).

I hope that I am not late with my solution and I can help you and other people with this question.

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

11 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

Related Questions

Use trigger collision or position check? 1 Answer

How to get the position of triggered object? 0 Answers

Get position of collision with triggers? 1 Answer

Troublesome collision detection when changing rigidbody.velocity directly 0 Answers

Time when 2 objects will touch 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