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 /
avatar image
0
Question by Bitpocketer · May 04, 2017 at 12:04 PM · script.navmeshnavmeshagentraycastingorienttopath

orienting navmesh to the normal surface of the ground experiences jerky motion

Hello devs, how are you doing, i'm facing a bit odd problem here, I'm using navmesh agent on my traffic car which has to move upwards and downwards on elevated track paved on terrain, I'm calculating normal of the surface and orienting my car with the normal of the surface, it does get oriented to the surface of the road but when ever it orients to the level of the surface,it experiences some jerky motion

I'm using quaternion.slerp for rotating vehicle from its current orientation to the level of the normal calculated, but i see no impact of as if during play mode while playing is paused, i drag the vehicle above the surface in the scene view and rotate it , and when i move the next frame, all of the sudden it gets oriented to the level of the ground, means no interpolations based on time.

 using UnityEngine;
 using System.Collections;
 
 public class TerribleAi : MonoBehaviour {
     public Transform[] destinations;
     NavMeshAgent Agenti;
     public int destinationcounter = 0;
     public int initialwaypoint = 0;
 
 
     public RCCAIWaypointsContainer waypoints;
     // Use this for initialization
     void Start () {
         destinations = waypoints.waypoints.ToArray();
         Agenti = gameObject.GetComponent<NavMeshAgent>();
         Agenti.SetDestination(destinations[destinationcounter].position);
     }
     Vector3 temp;
     Vector3 myrotation;
     Quaternion rotation;
     float distance;
     // Update is called once per frame
     void Update () {
         RaycastHit hit;
         Debug.DrawRay(transform.position, -transform.up * 5f, Color.red);
         if (Physics.Raycast(transform.position, -transform.up, out hit, 2f))
         {
             if ( hit.transform.gameObject.layer == 8)
             {
                  temp = Vector3.Cross(hit.normal, transform.forward);
                myrotation = Vector3.Cross(temp, hit.normal)*Time.deltaTime;
                rotation = Quaternion.LookRotation(myrotation);
              // transform.rotation = rotation;
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation,  3f);
                 Debug.Log("Applying rotation");
                 
             }
         }
 
      
 
         distance = Vector3.Distance(gameObject.transform.position, destinations[destinationcounter].position);
         if (distance <=2f)
         {
             destinationcounter++;
             Agenti.SetDestination(destinations[destinationcounter].position);
             
         }

it experiences jerky movement while going down the hill. what wrong am i doing here?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 04, 2017 at 08:15 PM

A couple things stand out to me:

  1. You're multiplying the 'myrotation' variable by Time.deltaTime, but that only multiplies it's magnitude... it should be a unit vector for what it's used for.

  2. In your Slerp call, you use 3f for the value of t. But the docs say that should be clamped to [0,1]. The reason is because 1 means instant change, while zero means no change. So, by setting it above one, you're basically making the call redundant.

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 Bitpocketer · May 05, 2017 at 06:22 AM 0
Share

@FortisVenaliter thanks for replying in details, I looked into my script and altered it, I'm not multiplying myrotation by Time.deltaTime any more, i also decremented the the value of t in slerp to 1 and tried 0.5 even still no luck.

the slope is continuous, can it happen due to lag in applying the calculated rotation to the current rotation, i mean, by the time the calculated rotation is applied, the vehicle is translated to another position for which the normal of the surface might differ from the previous one, I'm sorry if it makes no sense, how ever i tried using Rotatetowards, calculated angle between current rotation and calculated rotation and supplied that as a maxDeltaangle to Rotatetowards but no luck..

avatar image FortisVenaliter Bitpocketer · May 05, 2017 at 03:29 PM 0
Share

I would almost reduce it further, to 0.1-0.2. Can you post a video of the problem?

avatar image Bitpocketer FortisVenaliter · Jun 12, 2017 at 03:25 PM 0
Share

Thanks @FortisVenaliter the problem has been resolved by making an object a child of an agent and applying calculated rotation to it.

avatar image Collin-Farrell · May 05, 2017 at 03:20 PM 0
Share

I am having a similar problem and I suspect it is due to the fact that as the rotation or the object changes, so does it's raycast angle down from it to the mesh below. I believe in my case that the raycast sweeps across two different normals back and forth and keeps orienting itself to compensate for the change.

avatar image Bitpocketer Collin-Farrell · Jun 12, 2017 at 03:23 PM 0
Share

I figured out the navmesh agent takes care of it's rotation on it's own the one i calculated each frame was in conflict with the rotation calculated by agent on it's own, the best workaround I discovered is to have an actual object as a child of an agent, an agent could be anything, cube or sphere, and then ins$$anonymous$$d of applying rotation to the agent itself we apply rotation to the child of an agent and the jerky phenomenon takes place no more.

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

71 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

Related Questions

NavMeshAgent Not Working? 1 Answer

Tank not moving towards player 1 Answer

Make NavMesh move to random positions 1 Answer

Unwalkable nav mesh areas based on height map? 0 Answers

How NavMesh Cost can slow down NavMeshAgent's speed? 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