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 popnfresh24 · Jun 30, 2013 at 07:20 AM · instantiateplayerenemyradiusaround

Instantiate enemies around player

Hey everyone! First post, pretty new to Unity... I've had plenty of experience coding in Flash (AS3) and i know it's pretty similar to Javascript so i'm doin my best to my move skills from one to the other...

But i'm attempting to make a game, and my player is standing in a particular spot and can spin 360* to look in any direction... Basically i want to spawn enemies around him at a distance of 50m away from the player... and i need the enemies to be facing the player (as they walk forward towards him)

I saw some code to make the enemies spawn within a circle, but that doesn't keep them at a fixed distance.

So the player is in the middle, enemies spawn at a radius of 50 from the player (in any direction around the 360* and when Instantiated, they need to be facing the player...

How would i go about doing this?

Thanks guys! (and girls)

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
1

Answer by Drshk7 · Jun 30, 2013 at 08:40 AM

You could make a circle of empty objects around the player in 50m and name it, "Spawn1, Spawn2, Spawn3" and so on. Attach the empty objects to the graphic of the player. Make sure that the empty objects are not in the ground but in the air to fit the height of the enemy. The enemy might fall through the ground if it spawns in the ground. Next, make a script that instantiates the enemy in the spawn points that you just created (spawn1, spawn2, spawn3, ...). For the facing the player and moving towards the player use this code:

 var target : GameObject; //target
 var speed : int; //speed
 
 function Update()
 {
         transform.LookAt (target.transform); //look at target
         transform.Translate (0, 0, speed * Time.deltaTime); //move toward target
         //the enemy will not stop when it is touching the player so you might want to modify that. I am only writing the simple script.
 }

And you are done :D 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

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

Changing Player & Enemy Material when a button is pressed. 1 Answer

Rotate object around player when space is pressed. 1 Answer

Enemy's gather around the player.. How?! 2 Answers

Instantiate a cube around the player, with a maximum of distance 0 Answers

Adding a counter? 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