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 SirMcsquizy · May 05, 2014 at 04:02 PM · c#terrainai

2 questions about Terrain(AI on terrain)

Hi there!

So I just have a couple questions.

  1. I made a waypoint script which makes my enemy walk towards it. Which works amazing. However.... It also makes my enemies walk right through terrain to get to said waypoint. How can I make it so they can't go through terrain and instead have to walk over hills or go down them.

  2. When I put on a Rigidbody and use gravity, they just fall through the terrain... I have a trigger collider but i need it. because its the hitbox

If you could help me that would be great!

Thank you!

-Joel

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 Owen-Reynolds · May 05, 2014 at 06:43 PM 0
Share

This probably isn't a Terrain or an AI question. The movement AI just picks the waypoints, but actually walking towards it uses the same code as walking to a random point. Likewise, I'd guess that if the ground was made of huge sloped cubes, you'd have the same problems with falling through and walking through.

A common question here is players falling through the ground. Lots of reasons it does that, and lots of fixes, some simple. Also lots of "Why am I moving through objects" questions here. $$anonymous$$ost common problem is using Translate to move.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · May 05, 2014 at 04:09 PM

Hi, in my opinion:

  1. Most optimized way of keeping any ai above the ground would be using single raycast down. From it you get terrain or other object hit point, and you can set needed height for object itself.

  2. Haven't worked with a terrain for a while, as i remember there might be couple problems. First is, player is a bit inside/lower the terrain itself so it's just falling through. Other was terrain and colliders related, there was something terrain didnt like about mesh colliders, but i think this is not the case.

Comment
Add comment · Show 3 · 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 SirMcsquizy · May 05, 2014 at 04:15 PM 0
Share

@YoungDeveloper

  1. How would I do this? And how effective would this be?

  2. Its just a box colliders... would that be effecting it?

avatar image xortrox · May 05, 2014 at 05:18 PM 1
Share
 //Call this every frame after you move the NPC
 void StayOnGround()
 {
 
     Ray downwardsRay = new Ray(transform.position, Vector3.down);
     RaycastHit hit;
     if(Physics.RayCast(downwardsRay, out hit, 1.0f))
     {
 
         //You could check hit.collider.transform/tag to make sure
         //you're only trying to stand on the terrain
         transform.position = hit.point;
 
     }
 
 }
avatar image YoungDeveloper · May 05, 2014 at 05:24 PM 0
Share

Physics calculations will always take more than just single raycast. Just cast it down from your ai, best is to create new gameobject, child it and place it somewhere in the middle of your ai, and cast from it.

Effecting what? You said that your player/ai is falling if gravity enabled, it is probably because collider is inside terrain.

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

23 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Does anyone know ow to import World Machine tiled meshes into Unity? 0 Answers

AI line/field of sight with Raycast 0 Answers

Terrain: Change color/alpha of Layer (or how to let my texture-grass wither, become dry and brown) 0 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