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 alek123 · Dec 20, 2012 at 07:45 PM · objectaigamepathfinding

Object move back to first position

We have two object one stay on current position but second can move, when we press button this second will back in this same way. Is any easy way to do that ?

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

4 Replies

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

Answer by Statement · Dec 20, 2012 at 08:02 PM

Looks like you can get the path with this API:

http://docs.unity3d.com/Documentation/ScriptReference/NavMeshAgent.CalculatePath.html

Then you get a NavMeshPath. You can use it to find all the locations you need to visit and thus you should be able to navigate backwards as well by sampling the positions.

http://docs.unity3d.com/Documentation/ScriptReference/NavMeshPath.html

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 alek123 · Dec 20, 2012 at 08:09 PM 0
Share

Statement :) but this is good when we have clear way but in my game we have ladders,walls and others objects.

avatar image Statement · Dec 20, 2012 at 08:43 PM 0
Share

Sorry, I didn't realise that you were using the built in pathfinding. I don't read the tags that often. Just a sec, will update my answer.

avatar image alek123 · Dec 20, 2012 at 08:55 PM 0
Share

Can you tell me somthing more about this Nav$$anonymous$$esh?Any example or somthing ?

avatar image alek123 · Dec 20, 2012 at 09:08 PM 0
Share

Nav$$anonymous$$esh only for pro -.- becouse we need Nav$$anonymous$$eshAgent

avatar image Statement · Dec 20, 2012 at 09:32 PM 0
Share

Well I am not sure exactly what you already have working. But basically you could just store the locations that your character has visited and go backwards when you want to go back.

avatar image
0

Answer by JaydenM1997111 · Dec 21, 2012 at 12:53 AM

         public var OBJECT: GameObject;
         public var MoveOnX : float;
         public var MoveOnY : float;
         public var MoveAmount : float = 1;
         public var MoveSpeed : float = 2; //change to edit the ammount of time it takes to go back to default position
         public var DefaultPos : Vector3;
         public var NewPos : Vector3;
         
         function Start(){
             DefaultPos = transform.localposition; 
         }
         function Update () {
             MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
                MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
                NewPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);//reset to original position
                OBJECT.transform.localPosition = Vector3.Lerp(OBJECT.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);//make object go there
             
             if( Input.GetButtonDown("BUTTONYOUWANTCLICK")){
                  NewPos = new Vector3 (DefaultPos.x+WHATEVERVALUE, DefaultPos.y+WHATEVERVALUE, DefaultPos.z+WHATEVERVALUE);//change these to create your new position
                 OBJECT.transform.localPosition = Vector3.Lerp(OBJECT.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);//make object go there
             }
         }
 

Hope this helps :)

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

Answer by alek123 · Dec 21, 2012 at 12:53 AM

Statement :) but this is good when we have clear way but in my game we have ladders,walls and others objects.

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

Answer by cagezero · Dec 20, 2012 at 08:12 PM

Two of many techniques for doing this:

     GameObject object1;
     GameObject object2;
     float speed = 10;
     
     void Update() {
         
         //Do it immediately
         if (Input.anyKeyDown)
             ReturnToObject();
         //Do it slowly
         if (Input.anyKeyDown)
             StartCoroutine(ReturnToObject1());
     }
     
     //Do it immediately
     void ReturnToObject() {
         object2.transform.position = object1.transform.position;
     }
     
     //Do it slowly
     IEnumerator ReturnToObject1() {
         
         while(object2.transform.position != object1.transform.position) {
             
             object2.transform.position = Vector3.MoveTowards(object2.transform.position, object1.transform.position, Time.deltaTime * speed);
             yield return null;
         }
     }

Cache the transforms to make it more efficient.

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 alek123 · Dec 20, 2012 at 08:16 PM 0
Share

Yes but with this options our object will passes through other object right ? But we have walls , laders and other object on way. We need know when character should jump, go down,up,right

avatar image cagezero · Dec 20, 2012 at 08:29 PM 0
Share

That is quite a bit more complex. I have not worked with path finding, but it seems that is what you are looking for.

http://unity3d.com/unity/quality/ai

http://www.arongranberg.com/unity/a-pathfinding/

You might be able to implement some basic obstacle navigation by switching between basic movement and following cleverly placed splines, but that could potentially lead to jerky movement. Just a thought...

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

13 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

Related Questions

Pathfinding and AI for an RTS game 3 Answers

AI Pathfinding In A Certain Height 1 Answer

A* Pathfinding AIFollow in JavaScript? 0 Answers

NavMesh.SamplePosition returns point outside the NavMesh 0 Answers

"E" to grab an object... 3 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