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 gopics · Sep 09, 2014 at 09:56 AM · physicsraycastterraincamera rotation

How can i stop the car penetrating into the terrain

simply iam having one car model and try to move this using c# scripts. that code contain gets input from keyboard and move the car....its contains transform.rotate and transform.translate functions only.....but my car model penetrating into the terrain(mountain).i,e whenever the camera Z angle gets negative value the car penetrate into the terrain...could anyone help me to stop the penetration and give me the suggestion for car moving in ups and downs.......Thank u

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
1
Best Answer

Answer by ThePersister · Sep 09, 2014 at 10:06 AM

I'll give a shot at answering this question, but if I get it wrong, please add images of your scene and add your code, which would give us better insight of the situation.

One thing you should know is that doing a transform.translate sets the position in smooth lerps. However it can ignore the collision too.

First of all, for collisions you'll need a rigidbody on the Car object. Once you have a rigidbody, try using rigidbody.AddForce(); to move the car about, there are plenty of tutorials on this, so you should be fine :)

So maybe that's enough to solve your problem. But if it isn't, please add some scene images and code so we can give more accurate answers :) Best of luck! ;)

Comment
Add comment · Show 6 · 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 gopics · Sep 09, 2014 at 12:19 PM 0
Share

alt text

hai persister

my code and snap of project is attached here....am new to unity so please explain me clearly....whenever i tried to move the car its working but when it collide with mountain(i,e terrain ups and downs) it is penetrating.....help me to solve the problem...Thanking you

samplecodings.jpg (99.3 kB)
samplescreenshot.jpg (336.3 kB)
avatar image ThePersister · Sep 09, 2014 at 12:31 PM 0
Share

When you mark a Collider as a "Trigger" it will not collide with the rest of the world as stated in the Unity $$anonymous$$anual:

  • Triggers

    The scripting system can detect when collisions occur and initiate actions using the OnCollisionEnter function. However, you can also use the physics engine simply to detect when one collider enters the space of another without creating a collision. A collider configured as a Trigger (using the Is Trigger property) does not behave as a solid object and will simply allow other colliders to pass through. When a collider enters its space, a trigger will call the OnTriggerEnter function on the trigger object’s scripts.*

Aka,

  • Trigger Checked => No Collisions

  • Trigger UnChecked => Collisions

$$anonymous$$eaning, your car cannot be a Trigger (in your context it's not supposed to act like one, considering it's riding over terrain)

The same goes for your mauntains, terrain, make sure their trigger boxes are unchecked!!

I hope that helps, keep trying, keep asking, and if you succeed, please mark my answer as accepted :)

avatar image ThePersister · Sep 09, 2014 at 12:32 PM 0
Share

When you mark a Collider as a "Trigger" it will not collide with the rest of the world as stated in the Unity $$anonymous$$anual:

Triggers

The scripting system can detect when collisions occur and initiate actions using the OnCollisionEnter function. However, you can also use the physics engine simply to detect when one collider enters the space of another without creating a collision. A collider configured as a Trigger (using the Is Trigger property) does not behave as a solid object and will simply allow other colliders to pass through. When a collider enters its space, a trigger will call the OnTriggerEnter function on the trigger object’s scripts.

Aka,

  • Trigger Checked => No Collisions

  • Trigger UnChecked => Collisions

$$anonymous$$eaning, your car cannot be a Trigger (in your context it's not supposed to act like one, considering it's riding over terrain)

The same goes for your mauntains, terrain, make sure their trigger boxes are unchecked!!

I hope that helps, keep trying, keep asking, and if you succeed, please mark my answer as accepted :)

avatar image gopics · Sep 09, 2014 at 12:50 PM 0
Share

Thank u persist...but still my car rides throw the mountains....please give some coding explanation to stop the car penetrating into the mountains......am expecting some codings from u....

avatar image ThePersister · Sep 09, 2014 at 02:32 PM 0
Share

Hey gopics, what I'm trying to say is that your problem is not code related, it's all about that trigger checkbox in the inspector. So, I've gone as far as to make a little example project.

alt text

In the project there is:

  • Some Basic Environment, with a slope to give a "$$anonymous$$ountain"-like effect

  • A $$anonymous$$amikaze cube that launches itself into the wall, as a basic collision example.

  • A Player cube, that you can control with WASD, it's very basic, but sufficient for this.

The idea here is that all the collisions work, however, when you turn on the "Trigger Checkbox" on any of the colliders, you'll find that nothing collides with it anymore, it "Phases Through", because it's only a Trigger.

Anyway, I'm sure you'll be able to find out with this little project, I hope you appreciate it ;)

Download it here: https://mega.co.nz/#!LVxlDDIQ!1gJF95R7bck6DArU9SEDgt5LdBe9HTLd0fh2-0fvkNw

exampleproject_image.png (72.4 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Do Mesh Normals Influence Physics Behavior 1 Answer

Raycast to Terrain (Conditional Statements) 1 Answer

Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer

Raycasting 1000 times 1 Answer

Raycast and alighning to the terrain 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