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 VesuvianPrime · Jan 19, 2014 at 12:06 AM · collisionrigidbodykinematic

Kinematic Rigidbody collision detection

Hi all

I'm trying to implement some very basic collision detection for a simple game. For example: when a ball hits a block I want to calculate the normal of the collision and reflect the ball on that normal.

I've gone through the routine of setting up colliders to find that they don't really do anything unless you setup a RigidBody component. From there I discovered that I needed to set the RigidBodies to Kinematic in order for physics to stop interfering.

At this stage I have an OnTriggerEnter method that gets called to tell me that a Collider is present, but this doesn't tell me anything about the actual collision.

Furthermore, as I understand it, OnCollisionEnter is only called on non-kinematic RigidBodies.

tl;dr:

How do I get collision information without RigidBody physics simulation?

Thanks, Ves

Comment
Add comment · Show 3
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 getyour411 · Jan 19, 2014 at 12:09 AM 0
Share

Could you use physics.raycast, get the hit.point where the ray hit the collider in world space and calc normal from that?

avatar image VesuvianPrime · Jan 19, 2014 at 12:15 AM 0
Share

Thanks getyour411, that's not a bad idea

avatar image iwaldrop · Jan 19, 2014 at 12:57 AM 0
Share

You could probably freeze rotation and movement along all axes, leave is$$anonymous$$inematic set to false, and move it via the transform component (although it's just a hunch that I've not tested).

1 Reply

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

Answer by VesuvianPrime · Jan 19, 2014 at 02:54 AM

As suggested by getyour411 I was able to implement some raycasting between the objects in the collision. From here I could calculate the reflection vector and use that to adjust velocity:

 // Causes the ball to "bounce" against the given collider
 public void reflect(Collider other)
 {
     // We do a raycast to figure out the normal of the collision
     RaycastHit hitInfo = new RaycastHit();
     Vector3 direction = other.bounds.center - this.collider.bounds.center;
     if (!Physics.Raycast(this.collider.bounds.center, direction, out hitInfo))
         throw new Exception("Couldn't calculate normal");
     
     // Now we can calculate the reflection
     Vector3 velocity3 = new Vector3(this.__velocity.x, this.__velocity.y, 0);
     Vector3 reflection = Vector3.Reflect(velocity3, hitInfo.normal);
     
     this.velocity = new Vector2(reflection.x, reflection.y);
 }
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

Kinematic rigidbodies collision 0 Answers

Moving a player on a rigidbody platform that can collide 2 Answers

Rigid Body collision problem 2 Answers

How do I set up colliders and rigid bodies in a Descent space shooter? 1 Answer

Having issues with Rigidbody and CharacterController colision 2 Answers


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