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 Major · Apr 20, 2015 at 07:35 PM · raycasttransformpositionplayercontroller

Negative Positions Breaks Raycasts

For some reasons when I move my player controller so that its position is negative on the z axis the script controlling it just stops working, as soon as I move it back to positive it's like nothing ever happened. It seems that the problem is isolated in the grounding function which uses raycasts. The code looks like this:

 RaycastHit hit;
             if(Physics.Raycast(transform.position, new Vector3(0, -GetComponent<Collider>().bounds.extents.y, 0), out hit, GetComponent<Collider>().bounds.extents.y - colliderOffsety + 0.2f)){
                 isGrounded = true;
                 animator.applyRootMotion = true;
                 animator.SetBool("isGrounded", true);
             }else{
                 isGrounded = false;
                 animator.applyRootMotion = false;
                 animator.SetBool("isGrounded", false);
             }

I am unclear on what is causing this issue. Any help is appreciated. Thanks!

Comment
Add comment · Show 8
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 · Apr 20, 2015 at 08:48 PM 0
Share

It's nothing to do with your title. Raycasts are perfectly happy with negative #'s in the start, and/or in the direction. Think about a 3D game with 000 in the middle (common-ish) doing an "in front of me" raycast while facing southWest. Lots of negatives there, and they work.

It's probably something about your setup which is different when z`<`0. $$anonymous$$ight also copy some of those values into Inspector vars (for debugging,) to see if anything got knocked loose.

avatar image Major · Apr 20, 2015 at 11:33 PM 0
Share

No this is definitely within the engine itself. I cannot find any script in use that would cause this kind of effect. The whole system right now just seems unreliable and buggy.

avatar image Eno-Khaon · Apr 20, 2015 at 11:44 PM 1
Share

There's no need to jump to conclusions when you're experiencing a problem others aren't certain how to reproduce.

Am I correct in assu$$anonymous$$g that colliderOffsety is a constant and 0.2f is to correct it back to being (at least) slightly more than the distance to the ground?

$$anonymous$$ore importantly, I'm getting the impression that if, when your Z value is less than 0, you're no longer triggering collision properly (and, I'm assu$$anonymous$$g, on collision with the same platform as when Z is greater than 0)? If so, it being a problem with the raycasts may be a red herring. That said, it also means that we cannot provide any meaningful feedback or advice without other information relevant to the dilemma.

avatar image Major · Apr 20, 2015 at 11:49 PM 0
Share

There is a layered collision system in place on the character, that could be causing some issues. But as far as collision being correct when the z is negative seems to work fine.

avatar image Eno-Khaon · Apr 21, 2015 at 12:06 AM 0
Share

So it's only the Raycast itself that's not see$$anonymous$$g to connect (i.e. isGrounded remains false)? Or is there a problem with the CharacterController's behavior otherwise and that only occurs when at a negative Z value?

Sorry for the confusion, but the more detailed information you can offer, the better.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Lork · Apr 22, 2015 at 02:04 AM

In that case I would investigate along the following lines:

  1. In the negative Z, are you moving onto a different gameobject representing the ground? If so, double check to make sure it's not on the "Ignore Raycasts" layer.

  2. What you have for the direction parameter of the raycast shouldn't cause any issues (keyword shouldn't), but for simplicity and efficiency's sake, you should really be using a unit vector indicating the desired direction (eg. Vector3.Up * -1).

  3. Is colliderOffsety a constant or is it changed by something? If it becomes too high, the raycast may not be able to reach the ground.

  4. What position on the character does transform.position actually represent? Typically it'll either be the center or the bottom. If it's the bottom then the raycast is probably poking through the ground half the time. If that's the case you'll need to move the starting position up a little bit and reconsider your distance calculations.

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 Major · Apr 22, 2015 at 02:25 AM 0
Share

and of course it happens to be number 4, interestingly enough it only occurred when the z position was negative. Thanks Lork!

avatar image Bunny83 · Apr 22, 2015 at 02:51 AM 0
Share

I took the liberty of converting this comment into an answer.

@$$anonymous$$ajor: If your problem is solved you might want to either mark this answer as correct or close the question.

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

24 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 avatar image

Related Questions

Camera Follow Player using a path 0 Answers

how to tell what platform you're on. 1 Answer

Change position of camera on scene load? 1 Answer

calculating my position from another object 1 Answer

parented/constrained object transform lags when moving character 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