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
0
Question by relativ · Nov 25, 2016 at 08:47 AM · unity 5movementpathfindingrtsastar

Astar movement implementation not working properly

I'm working on a RTS Project and I'd like to use the A* Project by arongranberg to navigate aroud abstacles, etc.

The problem is, that the correct path is displayed in the scene, but the unit just jumps to 0-0-0. The image displays the correct path, the unit is still walking forwards, as is used this as a workaround to have some progress on my build script.

alt text

Scene view

As shown in the picture, the path is shown correctly, the unit moves straigt through the object.

So, I don't know where I made the mistake that leads to this behaviour. I'll post the script responsible for the movement.

 using UnityEngine;
 using System.Collections;
 using Pathfinding;
 using RTS;
 
 public class Unit : WorldObject
 {
 
     public float moveSpeed, rotateSpeed;
 
     protected bool moving, rotating;
     public  Vector3 destination;
     private Quaternion targetRotation;
     private object destinationTarget;    
     private Seeker seeker;
     private CharacterController controller;
     public Path path;
     public float nextWaypointDistance = 3;
     private int currentWaypoint = 0;
 
     protected override void Awake()
     {
         base.Awake();
     }
 
     protected override void Start()
     {
         base.Start();
         seeker = GetComponent<Seeker>();
         controller = GetComponent<CharacterController>();
     }
 
     protected override void Update()
     {
         base.Update();
         if (path == null)
         {
             Debug.Log("Kein Pfad");
             return;
         }
         if (currentWaypoint >= path.vectorPath.Count)
         {
             Debug.Log("Ende des Pfades erreicht: "+ path);
             return;
         }
         Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;
        // dir *= moveSpeed * Time.deltaTime;
         if (rotating) TurnToTarget();
         else if (moving) MakeMove(dir);
         if (Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
         {
             currentWaypoint++;
             return;
         }
     }
 
     protected override void OnGUI()
     {
         base.OnGUI();
     }
 
     public void newPath()
     {
         seeker.StartPath(transform.position, this.destination, OnPathComplete);
     }
     public void OnPathComplete(Path p)
     {
         Debug.Log("Pfad fertig. Fehler?: " + p.error);
         if (!p.error)
         {
             path = p;
             currentWaypoint = 0;
         }
     }
 
 
     public override void MouseClick(GameObject hitObject, Vector3 hitPoint, Player controller)
     {
         base.MouseClick(hitObject, hitPoint, controller);
 
         if (hasAuthority && player && player.human && currentlySelected)
         {
             if (hitObject.name == "Ground" && hitPoint != ResourceManager.InvalidPosition)
             {
                 float x = hitPoint.x;
                 float y = hitPoint.y + player.SelectedObject.transform.position.y;
                 float z = hitPoint.z;
                 this.destination = new Vector3(x, y, z);
                 Debug.Log("Start_Move");
                 StartMove(destination);
             }
         }
     }
 
     public virtual void StartMove(Vector3 _destination)
     {
         Debug.Log(_destination+"----------------");
         seeker.StartPath(transform.position, _destination, OnPathComplete);
         destinationTarget = null;
         targetRotation = Quaternion.LookRotation(destination - transform.position);
         rotating = true;
         moving = false;
 
     }
 
     private void TurnToTarget()
     {
         transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotateSpeed);
         Quaternion inverseTargetRotation = new Quaternion(-targetRotation.x, -targetRotation.y, -targetRotation.z, -targetRotation.w);
         if (transform.rotation == targetRotation || transform.rotation == inverseTargetRotation)
         {
             rotating = false;
             moving = true;
         }
         CalculateBounds();
     }
 
     private void MakeMove(Vector3 dir)
     {
         transform.position = Vector3.MoveTowards(transform.position, dir, Time.deltaTime * moveSpeed);
         if (transform.position == destination) moving = false;
         CalculateBounds();
     }
 
 
 }

I hope, you can find the problem here. If there is any information needed, please ask for it.

astar1.png (93.8 kB)
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 hexagonius · Nov 25, 2016 at 11:01 AM 0
Share

Ich würde mal raus loggen wenn nextWaypoint erhöht wird und wenn nextWaypointDistance tatsächlich 3 und der cube der zu sehen ist ein unit cube ist, dann würde ich sagen skipped er zu viele Wegpunkte.
P.S.: hab die deutschen Logs gesehen und musste einfach auf Deutsch antworten :)

avatar image relativ hexagonius · Nov 25, 2016 at 11:09 AM 0
Share

Hm, das logging sieht i.O aus. Hab auch schon einge viele Stunden nach dem Fehler gesucht, auch schon via peer review (3h via skype) Edit: es wird ja jedes update eine direction übergeben, die auch empfangen wird, eigentlich sollte der weg sich jedes mal ändern. ich hatte vergessen, im code wieder das dir zu nehmen, da die geradeaus bewegeung nurd drin ist, damit ich an einem anderen skript weiterarbeiten konnte. Wenn ich den übergeben Vect3 dir nehme ($$anonymous$$ake$$anonymous$$ove methode), springt die unit einfach zu 0-0-0

0 Replies

· Add your reply
  • Sort: 

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

132 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

Related Questions

Pathfinding Set Up In Unity2D 0 Answers

How do I make my A* script work with prefab enemies and make enemies move using the list created through A*? 0 Answers

How to move a cube by flipping using keyboard input 1 Answer

Display maximum movement range with a non-grid-based system 0 Answers

How to make spherical objects move in straight downward lines (unity 2D) 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