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 beginner 1 · Dec 14, 2010 at 04:26 PM · gameobjectai

check object if grounded

how can i check if the object is already grounded on the floor?

because my AI is flying while following its waypoint... i want him to stay on ground while following its path ...

here is the code

var waypoint:Transform[];

var speed:float=20;

private var cwaypoint : int;

var gravity=20.0;

private var grounded : boolean = false;

function FixedUpdate () {

if(cwaypoint<waypoint.length){ var target:Vector3=waypoint[cwaypoint].position; var moveDirection:Vector3=target-transform.position;

var velocity=rigidbody.velocity;

 if(moveDirection.magnitude&lt;1){
 cwaypoint++;

} else{ velocity=moveDirection.normalized*speed; }

} rigidbody.velocity=velocity;

transform.LookAt(target);

}

Comment
Add comment · Show 4
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 Justin Warner · Dec 14, 2010 at 04:36 PM 0
Share

Try adding a rigid body... Component>Physics

avatar image beginner 1 · Dec 14, 2010 at 04:40 PM 0
Share

oh i already added rigidbody but i didnt work

avatar image diabloroxx · Dec 14, 2010 at 04:42 PM 0
Share

Post the code to get better results. Especially the part where the AI moves.

avatar image Justin Warner · Dec 14, 2010 at 04:42 PM 0
Share

What waypoint system are you using?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by A Lee · Dec 14, 2010 at 04:43 PM

Yes, as mentioned, you should add a rigid body component to both the ground floor and the object that you want to check and see if it is grounded. You can then test for a collision between the two objects, and tell your AI what to do when a collision is detected, or not.

Comment
Add comment · Show 2 · 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 beginner 1 · Dec 14, 2010 at 04:50 PM 0
Share

im using terrain as the floor is it ok to add rigidbody on it?

avatar image Bampf · Dec 14, 2010 at 05:41 PM 0
Share

Terrain already has a collider, which is good enough. You don't need to add anything else to it. (Rigidbody is needed on objects that are controlled by physics.)

avatar image
0

Answer by Joshua · May 09, 2011 at 05:53 AM

I'd say simply cast a ray downward, see what the RaycastHit.distance is, and if it exceeds a certain range add a downward force.

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

No one has followed this question yet.

Related Questions

how can my gameobject stop shaking? 1 Answer

Help With Simple Waypoint System 0 Answers

Can my script instantiate an object then get that object for use in the script 1 Answer

Quick question. How do i get an object to come down once all AIs are destroyes and then when i come near it it loads a level 1 Answer

Problem with AI tracking object 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