Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Oct 06, 2016 at 04:02 PM by jacupiri for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by jacupiri · Sep 11, 2016 at 01:24 AM · raycastterrainraycasthitragdollterraincollider

NPC gets up inside terrain (disconsidering the terrain collider)

In my game humanoid NPCs have a lot of physics interaction, specially when the player casts spells with explosions or turning of the enemy's gravity. All these interactions trigger a ragdoll in the game object (by a specific set of scripts that you can see here: http://answers.unity3d.com/questions/1164842/from-animation-to-ragdoll-and-back.html#comment-1238107).

When they fall back to the ground, one of these ragdoll system's scripts sends a Raycast to detect where they are to blend the actual position to start a getting up animation.

What is going wrong is that the moment they start to get up, their root changes to a y = 0, and the getting up animation occurs at this height (not on the top of the terrain mesh, or on the top of a building), and they stay there, only getting back to terrain level afterwards, because of the NavMeshAgent.

Here is the part of the code I'm using that resets the NPCs root position, so the animation occurs exactly where their body is (it can be very far away, as a consequence of an explosion, for example):

 //Now cast a ray from the computed position downwards and find the highest hit that does not belong to the character 
                 RaycastHit[] hits=Physics.RaycastAll(new Ray(newRootPosition,Vector3.down)); 
                 newRootPosition.y=0;
                 foreach(RaycastHit hit in hits)
                 {
                     if (!hit.transform.IsChildOf(transform))
                     {
                         newRootPosition.y=Mathf.Max(newRootPosition.y, hit.point.y);
                     }
                 }
 
                 transform.position=newRootPosition;

Any help would be appreciated...

Comment
Add comment · Show 2
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 jacupiri · Sep 11, 2016 at 01:34 AM 0
Share

This is how it looks like:

alt text

When trying to solve it I cancelled the "newRootPosition.y=0" line, they still got inside the terrain, but not as deep as y = 0. They sank only around 0.3f (it looked a random number around that). Here's the pic:

alt text

I also tried to solve it putting a plane at the same height of the terrain collider at this part of the scenario, but nothing changed.

terrainerror1.jpg (462.8 kB)
terrainerror2.jpg (417.2 kB)
avatar image jacupiri · Sep 26, 2016 at 06:25 PM 0
Share

@crazy$$anonymous$$night @$$anonymous$$ikeNewall, does any of you have a clue on how to solve this?

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by jacupiri · Oct 06, 2016 at 03:42 PM

The problem was that the Raycast didn't always hit the terrain collider, so many times the NPC's "Getting up" animation would occur at y=0.

So I took the ragdolled state verification out of the Update () and established it as a variable (I still don't know why this worked, but it was a good guess) and I rippled of the comparison between the RaycastHit and the newRootPosition.y.

Now it is working!

No more underground animations!

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

Follow this Question

Answers Answers and Comments

91 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 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 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 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

I'm Trying to get a 3D Model to follow a Raycast 0 Answers

TERRAIN AND COLIDER on VRCHAT 0 Answers

RayCast enemy hp 0 Answers

Raycast Getting Caught 0 Answers

Swipe single object at a time upon touch, not swiping allover the screen 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