• 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 MattBradley · Nov 11, 2013 at 04:54 PM · rotationcollisionphysicsrigidbody

Camera and mesh not colliding

Hello,

I'm trying to get a camera to collide with a mesh, however at the moment I'm having difficulties getting the desired behaviour.

I am making an endless runner type game set in a tunnel. Each piece of the tunnel is comprised of sections featuring obstacles that the play must avoid to progress. To avoid these obstacles the player (camera) must rotate around tunnel.

The problem I have is that when the camera hits an obstacle in the tunnel it passes straight through it. That is unless I turn off all constraints on the rigidbody. If I do that the camera will collide with the obstacle but then a force is applied to both objects. What I would like is for the camera to collide with the obstacle, but no forces to be applied to either, the camera simply should not pass through the obstacle. This also applies to situations where the camera might need to jump onto a mesh within the level as well.

As mentioned above, if I freeze the position and rotation constraints both the camera and obstacle remain fixed on collision (no forces are applied), but the camera passes through. Both the obstacle and the camera have rigidbodies, and box and sphere colliders components respectively.

As far as I can tell this should be fairly simple, however my understanding of Unity's physics system is minimal so it's a lot more complicated than it should be!

Any assistance is greatly appreciated. Thanks.

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 MattBradley · Nov 13, 2013 at 01:12 AM

I've done some further investigation and found that my solution is likely to involve using a joint. At the moment I have a gameobject that controls the camera rotation at 0,0,0. The camera is a child of that object at 0,-20,0. I have a state machine that gets player input to rotate the camera around 0,0,0 with a -20 offset in the y axis.

I now have a fixed joint on the camera with the gameobject at 0,0,0 being the connected body. When I do this the obstacle no longer moves and the camera is generally in the right position unless I continue to try to rotate through the obstacle. If I do this the camera will act very strangely and not remain at 0,-20,0. Instead it rotates itself until it pings off the obstacle and loses its position.

Is there a way to fix this behaviour? I have considered turning off the ability to rotate once a collision has occurred and also to make the the camera rotate only by using forces, but both are a little scary!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 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

Related Questions

Rigidbody doesn't rotate after collision 3 Answers

Sphere / Box collision causes jitter 0 Answers

Physics - increase gravity speed without making balls fall through planes 1 Answer

Collision interpenetration and object getting stuck 1 Answer

Knock down moving target ridigbody from collision. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges