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 JuanseCoello · Apr 01, 2014 at 09:25 PM · colliderboolboundsgrounded

Why this script not working?

I have this script:

   public float threshold;

   private bool isGrounded;

   void OnTriggerEnter(Collision other) 
 {
    foreach(ContactPoint temp in other.contacts) {
     if(Vector3.Cross(temp.normal, Vector3.up) < threshold) {
         isGrounded = true;
     }
 }

}

The error says that operatos of < cant be applied to Vector3 and float, how can I fix this?

What it does is check the collider bounds to see if it is grounded.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Radivarig · Apr 01, 2014 at 11:30 PM

The left side of your if statement is a Vector3, since that is what Vector3.Cross() returns.

The error occurs because you can't compare set of 3 floats with 1 float.

Vector that is returned there is also normalized which means its magnitude equals 1 so no point in using someNormalizedVector.magnitude since it is a fixed value.

My first thoughts for ground checking would be raycasting or using collider.isGrounded which natively does not give usable results but I made a workaround for that, you can find the code and unitypackage working scene with separated raycast scene, char controller and both combined with explanations here. Good luck!

Radivarig

Comment
Add comment · Show 5 · 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 JuanseCoello · Apr 02, 2014 at 01:06 AM 0
Share

Can you put it in a code please? I am new to raycasting.

avatar image JuanseCoello · Apr 02, 2014 at 01:06 AM 0
Share

I have tried that code but it doesnt work.

avatar image JuanseCoello · Apr 02, 2014 at 01:08 AM 0
Share

I put this script but somehow it doesnt works when the character walks on slopes.

void IsGrounded() {

     RaycastHit hitInfo;
     if (Physics.Raycast(transform.position, Vector3.down, out hitInfo))
     {
         if (hitInfo.normal.y > InclinatedSlopes)
         isgrounded = true;

     }

     else isgrounded = false;
 }
avatar image JuanseCoello · Apr 02, 2014 at 01:09 AM 0
Share

I mean sorry this is the code I used, the one before doesnt work either.

void IsGrounded() {

     if (Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f))
         isgrounded = false; // Debe mantenerse en true
     else isgrounded = true;
 }
avatar image Radivarig · Apr 11, 2014 at 05:41 AM 0
Share

Here you go, the project and the forum thread

avatar image
0

Answer by thornekey · Apr 03, 2014 at 03:56 AM

OnTriggerEnter has to be Collider not Collision

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 JuanseCoello · Apr 11, 2014 at 04:25 AM 0
Share

Thanks Radivarig, but I cant find the links. :(

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

22 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

Related Questions

Make Collider equal to renderer bounds? 2 Answers

Grounded Only on One Layer 1 Answer

How would i find the center of an object with a Y axis offset to find the center on the top face? 1 Answer

Unity Height Glitch (explained) 1 Answer

Calculating collider corners 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