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 /
avatar image
1
Question by greatness · Aug 03, 2016 at 04:04 AM · unity 5scripting problemaicarstandard assets

I don't understand how to use Car AI in Standard Assets.

Ok, I have downloaded the Standard Assets for Unity 5 and I don't understand how the Car AI really works. True, I have solved some irritating issues in the past few hours :(. For example, I put a Waypoint Circuit script to my Waypoint Target Object and put it outside of the parent, allowing it to break prefab instance or whatever its called. Then, I clicked assign using all children. I see some sort of yellow curve and I put way points where I want the car to go to . The curve is weird and is some of it is hanging on the open void. What does this curve even do? How ever some is on the floor. I can't post a screenshot now because my computer is acting weird so I am trying my best to describe it. Anyways, when I start the game, the car ai goes into a completely random direction(not towards the curve) and drives off the road. Also, this beautiful message in the console shows:

Look rotation viewing vector is zero UnityEngine.Quaternion:LookRotation(Vector3) UnityStandardAssets.Utility.WaypointProgressTracker:Update() (at Assets/Standard/Standard Assets/Utility/WaypointProgressTracker.cs:98)

Also, here is some code that I think may contain the error.

 using System;
 using UnityEngine;
 
 namespace UnityStandardAssets.Utility
 {
     public class WaypointProgressTracker : MonoBehaviour
     {
         // This script can be used with any object that is supposed to follow a
         // route marked out by waypoints.
 
         // This script manages the amount to look ahead along the route,
         // and keeps track of progress and laps.
 
         [SerializeField] private WaypointCircuit circuit; // A reference to the waypoint-based route we should follow
 
         [SerializeField] private float lookAheadForTargetOffset = 5;
         // The offset ahead along the route that the we will aim for
 
         [SerializeField] private float lookAheadForTargetFactor = .1f;
         // A multiplier adding distance ahead along the route to aim for, based on current speed
 
         [SerializeField] private float lookAheadForSpeedOffset = 10;
         // The offset ahead only the route for speed adjustments (applied as the rotation of the waypoint target transform)
 
         [SerializeField] private float lookAheadForSpeedFactor = .2f;
         // A multiplier adding distance ahead along the route for speed adjustments
 
         [SerializeField] private ProgressStyle progressStyle = ProgressStyle.SmoothAlongRoute;
         // whether to update the position smoothly along the route (good for curved paths) or just when we reach each waypoint.
 
         [SerializeField] private float pointToPointThreshold = 4;
         // proximity to waypoint which must be reached to switch target to next waypoint : only used in PointToPoint mode.
 
         public enum ProgressStyle
         {
             SmoothAlongRoute,
             PointToPoint,
         }
 
         // these are public, readable by other objects - i.e. for an AI to know where to head!
         public WaypointCircuit.RoutePoint targetPoint { get; private set; }
         public WaypointCircuit.RoutePoint speedPoint { get; private set; }
         public WaypointCircuit.RoutePoint progressPoint { get; private set; }
 
         public Transform target;
 
         private float progressDistance; // The progress round the route, used in smooth mode.
         private int progressNum; // the current waypoint number, used in point-to-point mode.
         private Vector3 lastPosition; // Used to calculate current speed (since we may not have a rigidbody component)
         private float speed; // current speed of this object (calculated from delta since last frame)
 
         // setup script properties
         private void Start()
         {
             // we use a transform to represent the point to aim for, and the point which
             // is considered for upcoming changes-of-speed. This allows this component
             // to communicate this information to the AI without requiring further dependencies.
 
             // You can manually create a transform and assign it to this component *and* the AI,
             // then this component will update it, and the AI can read it.
             if (target == null)
             {
                 target = new GameObject(name + " Waypoint Target").transform;
             }
 
             Reset();
         }
 
 
         // reset the object to sensible values
         public void Reset()
         {
             progressDistance = 0;
             progressNum = 0;
             if (progressStyle == ProgressStyle.PointToPoint)
             {
                 target.position = circuit.Waypoints[progressNum].position;
                 target.rotation = circuit.Waypoints[progressNum].rotation;
             }
         }
 
 
         private void Update()
         {
             if (progressStyle == ProgressStyle.SmoothAlongRoute)
             {
                 // determine the position we should currently be aiming for
                 // (this is different to the current progress position, it is a a certain amount ahead along the route)
                 // we use lerp as a simple way of smoothing out the speed over time.
                 if (Time.deltaTime > 0)
                 {
                     speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude/Time.deltaTime,
                                        Time.deltaTime);
                 }
                 target.position =
                     circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor*speed)
                            .position;
                 target.rotation =
                     Quaternion.LookRotation(
                         circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor*speed)
                                .direction);
 
 
                 // get our current progress along the route
                 progressPoint = circuit.GetRoutePoint(progressDistance);
                 Vector3 progressDelta = progressPoint.position - transform.position;
                 if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                 {
                     progressDistance += progressDelta.magnitude*0.5f;
                 }
 
                 lastPosition = transform.position;
             }
             else
             {
                 // point to point mode. Just increase the waypoint if we're close enough:
 
                 Vector3 targetDelta = target.position - transform.position;
                 if (targetDelta.magnitude < pointToPointThreshold)
                 {
                     progressNum = (progressNum + 1)%circuit.Waypoints.Length;
                 }
 
 
                 target.position = circuit.Waypoints[progressNum].position;
                 target.rotation = circuit.Waypoints[progressNum].rotation;
 
                 // get our current progress along the route
                 progressPoint = circuit.GetRoutePoint(progressDistance);
                 Vector3 progressDelta = progressPoint.position - transform.position;
                 if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                 {
                     progressDistance += progressDelta.magnitude;
                 }
                 lastPosition = transform.position;
             }
         }
 
 
 }
 

I shortened the code down a bit, but didn't shorten it too much in fear that I might accidently not show you some code that might be relevant.

In brief, I really really need a tutorial on how to use the Car AI in the standard assets. Please provide information on how to use it or provide links to a tutorial. Cheers.

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
3

Answer by greatness · Aug 05, 2016 at 02:33 AM

never mind, I found out the cars can only go in a way point system. To do things correctly, first drag in the car ai prefab and create a new empty game object(make sure it is NOT a child of the car ai prefab) and give it a waypoint circuit script. Then add a bunch of children to this gameobject and click assign using children on the parent. This will create a path. Adjust the path and your car will go on that path. Hurray. However, it sucks that the Standard Assets had no navmesh thingy.

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

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

How to get variables of a behavior tree with RAIN AI 0 Answers

Help with Unity Vehicle Assets: Car isn't working at all 2 Answers

Case of the Haunted Standard Car Assets? 0 Answers

Whats wrong with my car auto park AI scripts?,What am I missing from my car auto park code? 0 Answers

About generated dlls and Unity 1 Answer


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