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
0
Question by DNP · Jul 25, 2012 at 06:59 PM · collisionterraintypecollideground

Collision Help

Why wont this work? its supposed to see if the type of ground is grass. and if its grass it changes the interger to one. then if its wood, change it to two. i couldnt find out how to get it to detect the tag to see if it was grass, so i just used a string in a seperate script. if you could remake it so it checks the tag that would be great!

 var groundType : int;
 
 function OnCollisionEnter(collision : Collision){
     if (collision.GetComponent(GroundTypeScript).GroundType == "Grass"){
       groundType = 1;
     }
  else if (collision.GetComponent(GroundTypeScript).GroundType == "Wood"){
        groundType = 2;
   }
 }
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 Seth-Bergman · Jul 25, 2012 at 07:14 PM

To check by tag:

var groundType : int;

 function OnCollisionEnter(collision : Collision){
     if (collision.gameObject.tag == "Grass")
       groundType = 1;
  else if (collision.gameObject.tag == "Wood"){
        groundType = 2;
   }
 }

this should work if both objects have a collider (or character controller), not set to trigger..

the player probably should also have a rigidbody

for detailed info of what combos will/won't send collision message see this link:

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

check out the matrix at the bottom, it should help...

Comment
Add comment · Show 11 · 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 DNP · Jul 25, 2012 at 07:21 PM 0
Share

It still wont work when the character controller touches the terrain or the wood floor.

avatar image Seth-Bergman · Jul 25, 2012 at 07:26 PM 1
Share

are the objects properly tagged?

try adding a Debug.Log:

function OnCollisionEnter(collision : Collision){

Debug.Log("entered collision");

 if (collision.gameObject.tag == "Grass")

also, you probably need to add a rigidbody

again, check the matrix at the link above for specifics

avatar image DNP · Jul 25, 2012 at 07:36 PM 0
Share

It seems to work now. but the rigidbody makes my first person controller move weird.

avatar image Seth-Bergman · Jul 25, 2012 at 07:40 PM 0
Share

you could put the rigidbody on the other objects ins$$anonymous$$d, and set them to kinimatic if you don't want them to be affected by physics (if it's the floor, you probably don't)

avatar image DNP · Jul 25, 2012 at 07:47 PM 0
Share

Well this is a footstep script. so it would be very complicated to have the floor have a rigidbody.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer

Camera Colliding with Terrain 1 Answer

Irregular ground collision 1 Answer

Detail Mesh doesn't collide. 2 Answers

Terrain collision and specific collision problems . 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