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 Dr_GeoFry · Jun 14, 2013 at 07:10 AM · transformpositionenemystart

How to Return Enemy to startPosition

Hi everybody,

I'm an amateur and a hobbyist, so I appreciate any and all help. What I am hoping to accomplish is have the enemy start at a certain point, pursue the hero, and if the hero flees, have the enemy return to its starting point.

Off the top of my head, I am thinking the coding should look something like this, but I am not getting the results that I want. I will provide code that displays what I am thinking...

 if (distance > alertDistance)
     {
     ReturnToStart();
     }

then further down into the function, I'd like the enemy to be satisfied that the hero has left the problematic area, rotate back to the starting point, and return to the starting point. This is where the code gets away from me because on top of the basic concept, there is the additional problem of trying to avoid obstacles in the way. I'll leave that until later. I only really want the simplest version of this concept. This is kind of what I think makes sense:

 function ReturnToStart()
 {
             attackTimer = 0.0;
             //rotate to look at the start position
             var rotation = Quaternion.LookRotation(target.position - transform.position);
             var enemyTransform = transform.position;
             enemyTransform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
             Quaternion.LookRotation(startPosition - enemyTransform); 
              
             //move back to start position
             enemyTransform += enemyTransform.forward * moveSpeed * Time.deltaTime;
 }

don't worry about attackTimer, it serves a function in the code for something else than what applies here. Please forgive the gaps in thinking or if this is irrational or anything like that. I was trying to wrap my head around a few concepts, and this is what I thought made sense.

THANK YOU ALL SO MUCH!!

Comment
Add comment · Show 3
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 bodec · Jun 14, 2013 at 10:47 AM 1
Share

assu$$anonymous$$g your enemy is sitting a single place the most simple way is to store is spawn spot and when distance is far enough return him to the vector3 you have assigned using a simple lerp I think or a smoothdamp function for where he is and where you want him and use transform.lookat for rotation.

avatar image bodec · Jun 14, 2013 at 07:58 PM 0
Share

You did ask for the simplest way and said you were not worried about the obstacles atm so I gave you the simplest way to do it

avatar image Dr_GeoFry · Jun 14, 2013 at 08:29 PM 0
Share

you're right. I did ask for the simplest way. I also wanted to have my code exa$$anonymous$$ed for any mistakes, with particular attention paid to the enemy rotating towards the start point and then walking back to the start point. That is what I meant when I asked for the simplest way to solve my problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hotshot03 · Jun 14, 2013 at 11:25 AM

var enemyStartPosition; function Start() { enemyStartPosition = enemyTransform.transform.position; }

function ReturnToStart() { enemyTransform.transform.position = enemyStartPosition; }

Comment
Add comment · Show 1 · 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 Dr_GeoFry · Jun 14, 2013 at 07:14 PM 0
Share

@aldonaletto @Benproductions1 I'm wondering if you might take a look at my code, and give me some insight into where I went wrong in its logic. $$anonymous$$UCH APPRECIATED!

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

16 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

Related Questions

Return Enemy To Start Position 1 Answer

How can I get a GameObject's transform in game and set that to a variable? 1 Answer

Remember the start coordinates? 2 Answers

How to move an GameObject to a random position in a defined area? 1 Answer

Enemy position transform 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