• 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 /
This question was closed Dec 20, 2014 at 08:24 AM by alucardj for the following reason:

other : question is too broad / unspecific

avatar image
2
Question by PigInATuxedo · Dec 20, 2014 at 01:25 AM · collisionobjecttouchgame

How do I check if an object is touching another object?

How do I check if the player is touching any object?

What I am trying to do is make it so I can jump if I am touching anything.

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 alucardj · Dec 20, 2014 at 08:22 AM 0
Share

Start in the Unity Learn section : http://unity3d.com/learn/tutorials/modules

1 Reply

  • Sort: 
avatar image
6

Answer by JackMini36 · Dec 20, 2014 at 02:12 AM

Use a collider on both objects. Also tag the objects, for example one could be "floor" and the other "player". Then use the OnCollisionEnter function to act accordingly if certain objects collide.

http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

for example if you want to be able to jump if your players touch on anything:

 void OnCollisionEnter (Collider other) 
     {
         canJump = true;
     }
 
 void OnCollisionExit (Collider other) 
     {
         canJump = false;
     }

then in your player script, enable the player to jump only if canJump is true.

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 PigInATuxedo · Dec 20, 2014 at 05:13 AM 0
Share

Does this work in c#?

avatar image getyour411 · Dec 20, 2014 at 05:27 AM 0
Share

Yep it does.

avatar image warhammercasey · Oct 15, 2015 at 11:56 PM 1
Share

I just get an error saying This message parameter has to be of type: collision.

avatar image luckynamal · Dec 07, 2015 at 03:11 PM 1
Share

i am modifing above answer a little bit. void OnCollisionEnter (Collision other) { canJump = true; }

void OnCollisionExit (Collision other) { canJump = false; }

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

31 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Now I want that when the object appears I press the letter "E" to get him. and I want this object in 3d q appear in the right corner of the screen, to symbolize that I took. gui not want do not want a texture 2d want the object in 3D. 0 Answers

how to morph character on collision enter with gameobject 1 Answer

Basic Collision, Object + First Person 2 Answers

Player collision activates GO 0 Answers

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