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 Whelandrew · Nov 20, 2011 at 03:15 AM · collisionpositiononcollisionentercontact.point

Position of a Collision

I am using a plug-in that handles collision detection of my sprites in a 2D environment. I would like to access the contact.point in OnCollisionEnter, but cannot seem to find a method to extract the information without calling the OnCollisionEnter. Any thoughts?

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
0

Answer by aldonaletto · Nov 20, 2011 at 03:40 AM

Contact points are only reported in OnCollisionEnter/Stay, both occurring in the physics cycle (50 times per second). But if you want to have the contact points available outside these functions, you can make a copy inside them and access the copy in any function:

var contact: ContactPoint; // saved contact point

function OnCollisionEnter(coll: Collision){ contact = coll.contacts[0]; // save the first contact point } Copying the first contact is faster and solves most cases, but you can copy the entire contacts array as well:

var contacts: ContactPoint[]; // contact points saved

function OnCollisionEnter(coll: Collision){ contacts = coll.contacts; // save contact points }

Comment
Add comment · Show 5 · 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 Whelandrew · Nov 20, 2011 at 10:30 PM 0
Share

Yeah, that's right. Thanks for helping me clear my head

avatar image Whelandrew · Nov 22, 2011 at 12:39 AM 0
Share

Okay... not quite there yet. Orthello2D uses OnTriggerEnter to register collision detection. I can only get contacts through OnCollisionEnter. Can I bridge these two functions?

avatar image aldonaletto · Nov 22, 2011 at 01:10 AM 0
Share

That's bad - OnTriggerEnter only passes the collider hit, not the hit point. Why do you need the collision point? To deter$$anonymous$$e the impact direction?

avatar image Whelandrew · Nov 22, 2011 at 01:20 AM 0
Share

A little creature attaches itself to a building upon collision. Right now, I just have the creature setup to attach at the position it is located upon hitting the building. Since the collision point is different than the transform.position, the creature has the appearance of being just slightly off from where it collided. So, it's attached, but it looks like it's floating in the air.

avatar image Srbhunter · Mar 02, 2014 at 01:11 AM 0
Share

Thank you! :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to check if an game object had been collided with another game object form its left or right side? 1 Answer

Direction isn't changing after multiplying it *-1 0 Answers

Collision with no contact? 2 Answers

Rigidbody not calling OnCollisionEnter 1 Answer

OnCollisionEnter called once even with multiple contacts 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