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 /
avatar image
0
Question by iPedro · Oct 01, 2011 at 10:29 PM · collisionphysicscollisiondetectionistriggeriskinematic

Detect collision and prevent intersection

I m trying to detect the collision of two objects (Player and Rock) I want to be able to handle the collision event (OnTriggerEnter) but also prevent the objects from intersecting.

Example:

  1. the player runs into the rock,

  2. the rock knows its the player (OnTriggerEnter or similar)

  3. The player cannot move through the rock, stops right at it's edge as if trying to walk through a wall

  4. The rock does not move

I have tried all variations of Is Trigger, Is Kinematic and both objects have rigid bodies attached but the closest I get is one of the objects spinning off into the abyss. I have even tried using OnTriggerEnter and OnTriggerStay to set the position of the player to the position it was at when the collision first occurred which works but looks like ass.

How can I detect the collision in my script but keep both objects from driving over/through each other?

Thank you very much for any help!

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
Best Answer

Answer by save · Oct 01, 2011 at 10:33 PM

You mean like OnCollisionEnter? Just don't use trigger and make sure to use a collider on both objects. The player needs to have a rigidbody and be completely controlled by physics (stay away from transform.position and translate).

Comment
Add comment · Show 4 · 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 iPedro · Oct 01, 2011 at 10:59 PM 0
Share

I don't understand why I post a response here and it doesn't show up with no indication of error at all. This is my second time responding to your answer, lets hope it gets posted....

The player can't be completely controlled by physics as it is controlled by the player. When I implement your answer and the player collides with the rock it spins off into the abyss and I lose control. The player is also controlled using translate as it is the keyboard that is used to control the player.

The effect I am trying to achieve is I move my player forward and he hits a rock. The rock knows what hit it (a player, a bullet, a butterfly) but since I am controlling the player I can just keep walking him right into that rock. He doesn't all of a sudden spin off in some other direction, the rock all of a sudden doesn't spin off in some direction it is just like trying to walk through a wall.. does this make sense or am I not understanding what you are saying?

Thanks!

avatar image iPedro · Oct 01, 2011 at 11:06 PM 0
Share

Final note in regards to the above. I have tried using Freeze position and freeze rotation as well. If all are frozen then I can just walk right through/over the rock.

avatar image save · Oct 01, 2011 at 11:42 PM 0
Share

It doesn't get posted because members with higher karma needs to approve your post before it becomes public.

You can't use translate and physics, the physics engine won't calculate anything else than physic events. You can control the player just via physics, make the inputs fire off physic events ins$$anonymous$$d of translation/positioning.

Have a look at the rigidbody class.

avatar image iPedro · Oct 02, 2011 at 12:17 AM 0
Share

Thank you for both explanations :) looks like using rigidbody is the way to go then.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Collision Handling (Pushout and Sliding) for Customized Collision Object? 0 Answers

How to detect collision with isTrigger enabled object, from the pont of the isTrigger disabled object 1 Answer

Probably another "bullet through paper problem". Jerks, teleports, and other problems 0 Answers

How to check if a collision impact is perpendicular with the velocity of the collider? 0 Answers

Collision 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