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 Hydropulse17 · Jul 19, 2014 at 04:14 PM · javascriptcollisionterrainoncollisionenteroncollisionexit

How can I make my truck drive on terrain and on bridge

I have my game set up to where if the player is driving and loses contact with the terrain, he loses control of the vehicle. Basically the logic is that all user input code is wrapped in an if statement checking if groundContact is true. OnCollisionEnter, if the object you're colliding with equals "Terrain," groundContact is true. OnCollisionExit, if the object you WERE colliding with equals "Terrain," groundContact is false. I tried making it like this instead:

 function OnCollisionEnter(grounder : Collision){
     if(grounder.gameObject.name == "Terrain" || grounder.gameObject.name == "Bridge"){
         groundContact = true;
     }
 }
 
 function OnCollisionExit(grounder : Collision){
     if(grounder.gameObject.name == "Terrain" || grounder.gameObject.name == "Bridge"){
         groundContact = false;
     }
 }

I even tried checking both of them at the same time by a user defined tag and set both the bridges and the terrain to said tag. I know it's that OnCollisionExit thats breaking it. The player transitions onto the bridge from the Terrain without ever leaving the ground, but since it exits the collision with Terrain, it sets groundContact to false while you're also colliding with Bridge. Any ideas?

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 Lo0NuhtiK · Jul 19, 2014 at 05:19 PM 0
Share

Try it using OnCollisionStay ins$$anonymous$$d of OnEnter, and maybe it'll fire right so if you lose contact on exit/re-enter it won't matter.. and/or you could also do some raycasting to check your grounding... and/or you could use wheel colliders and http://docs.unity3d.com/ScriptReference/WheelCollider.GetGroundHit.html to check and see if all of your wheels aren't hitting the right ground then you're not grounded.

Edit : just in case you try the wheel thing, I'd only check one at a time so you don't waste time with others if it's not necessary. Check wheel1, if it's good, then screw the rest cuz we got one touching and thats good enough; if its not touching, check wheel2 and do the same... and so-on.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by DarkGamer67 · Jul 19, 2014 at 07:55 PM

I wouldn't use the name. It's better to use Tags. That's how you define Tags : http://docs.unity3d.com/Manual/Tags.html

Your script would look like this (if you tag your Terrain and Bridge ground):

     function OnCollisionEnter(grounder : Collision){
     if(grounder.gameObject.tag == "ground"){
     groundContact = true;
     }
     }
      
     function OnCollisionExit(grounder : Collision){
     if(grounder.gameObject.tag == "ground"){
     groundContact = false;
     }
     }

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnCollisionExt not working/ Alternate collision detection 1 Answer

OnCollisionEnter not working. 2 Answers

Collision with Terrain 2 Answers

Raycast to Terrain (Conditional Statements) 1 Answer

Checking to see if two objects are colliding. 2 Answers


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