• 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 K_alqallaf · Dec 04, 2013 at 11:34 PM · terrain gen

How to make the car move slower in the terraing and faster in the street

Hello mates, I made a car game. I tried to make the car moves faster when it is on the street, and slower when it is on the terrain or grass. but it does not work because I could not know how to tell the if statement about the colliders that I am using.

if () // here is the problem // I tried to use something like (collider.name == "terrain") // but it also does not work because it did not recognise what happen to it and which collider is touching it { maxSpeed = 250; } else { maxSpeed = 100 ; }

I also tried, function OnTriggerEnter(other : Collider) but the way I did it could be wrong

I did not know how can I search for such as this problems in unity website

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 robertbu · Dec 04, 2013 at 11:35 PM 0
Share

Can we see the rest of your code where you attempted to make this check? Have you tried raycasting down and checking the name or tag on the object hit?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by EX_Darius · Dec 04, 2013 at 11:53 PM

Make sure one of the objects that collide have the "Is trigger" option enabled in the inspector.

from there you could do:

 void OnTriggerEnter(collider other)
 {
 // your script
 }
Comment
Add comment · Show 1 · 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 K_alqallaf · Dec 22, 2013 at 11:44 AM 0
Share

check what i said bellow, thanx

avatar image
0

Answer by Exalia · Dec 04, 2013 at 11:50 PM

Firstly

I recommend using Compare.Tag("terrain")

It uses less memory.

Secondly

If you want to do it with collision detection you'll need to tag your "street" and "terrain" then attach a similar script to your car (make sure all these objects have a collider component)

     void OnCollisionEnter(Collider col)
     {
         if(col.CompareTag("Terrain"))
         {
             maxSpeed = 100;
         }
         else
         {
             maxSpeed = 250;
         }
     }

That should work, however...

Hopefully this is a good suggestion :

Don't use colliders for this, instead use physic materials. Create a physic material for your street and for your grass, and play with those values untill you get the right effect. I recommend using gameObject.rigidbody.AddForce(); for your movement and letting the physic material do the rest.

Goodluck with your project :)

Comment
Add comment · Show 1 · 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 K_alqallaf · Dec 22, 2013 at 11:44 AM 0
Share

check what i said bellow, thanx

avatar image
0

Answer by K_alqallaf · Dec 22, 2013 at 12:35 PM

thanks both of you for trying to help me. I tried what u said but the problem is the fact it is not recognizing the car. I tried doing something smiler and easier like collecting the money. but it also does not work. the car just pass the through the money and its not collected. the money collier is on trigger. the car is tagged as (Player)

function OnTriggerEnter( other : Collider ) { if (other.gameObject.tag == "Player") { Destroy(other.gameObject); } }

I hope this makes sense?

thanks again for trying

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Seeding perlin functions 1 Answer

Set Random.seed for noise generator 1 Answer

Terrain scale differs from object scale? 0 Answers

How can I create voxel based terrain ? 2 Answers

Is There a heightmap making/generating tool? 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