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 MrJesterXiii · Apr 13, 2013 at 09:40 PM · movementenemyshooterturretspawner

Urgent Help Needed: Enemy Spawning and Movement

Hey guys, I could really use a hand.

I am making a turret based shooter and i am struggling to figure out how to make the enemies spawn in the distance and then gradually move towards the player. (kind of like a first person space invaders)

I just want the enemies to appear (from a wormhole, but i can handle that bit myself) and travel towards the player. I have 3 different enemy types but i imagine i can just replace the enemies within the script as and when i need. I also think i understand that i need a game object to representa spawn point and the enemies need to be drawn to a player object, but thats literally all i have.

I can see this as being a slightly simple script as there isnt really any enemy AI persay, i just have no grasp on coding and have hit a bit of a rut.

I really just have a clean slate so any help you guys can give me doesn't need to function with any existing code.

Hope i've explained well enough,

Thanks in advance, super grateful.

Cheers

Jester

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
0

Answer by zero_rogue · Apr 13, 2013 at 10:43 PM

If your wanting just the basics here it is,

For creating enemies you want to make a script and attach it to a GameObject that is at the position you want them to spawn at.

Spawning Script:

 //visible vars
 var Enemies : GameObject[];//put your 3 enemies here
 var DelayTime : float;//put the time between enemies spawning (1 or 2 seconds)
 var TotalEnemies : int;//total ammount of enemies to spawn.
 
 //private vars
 private var NextSpawn : float;
 private var TotalSpawn : float;
 
 
 function Update()
 {
     if(TotalSpawn >= TotalEnemies) return;
     if(Time.time > NextSpawn)
     {
         //set next spawn time.
         NextSpawn = Time.time + DelayTime;
         //Create a random enemy at this location
         Instantiate(Enemies[Random.Range(0,Enemies.length)],transform.position,Quaternion.identity);
         //add to total spawn.
         TotalSpawn++;
     }
 }

To get the enemies to move use this.

 //visible vars
 var Player : Transform;//player
 var Speed : float;
 
 function Start()
 {
     //Make sure you tag your player with the "player" tag!
     Player = GameObject.FindWithTag("Player").transform;
 }
 
 function Update()
 {
     transform.position = Vector3.Lerp(transform.position,Player.position,Time.deltaTime * Speed);
 }

This should make the enemy continually move towards player. I didn't bug-check any of it but it should work. Feel free to mod it to your needs, there is plenty you can add to this to give it a lot of versatility. Although you'll likely be back here a lot since there are much difficult things further ahead for a game like you describe. Keep with it and Good Luck!

Comment
Add comment · Show 3 · 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 MrJesterXiii · Apr 13, 2013 at 11:19 PM 0
Share

Thanks for replying, the spawner works perfectly. But i cant seem to figure out what to attach the enemy follow script to, as there are no enemies in the hierarchy before the game is played.

How do i go about adding the script? (i realised the same issue will apply with adding colliders for the bullets to hit as i cannot add anything to the enemies)

avatar image zero_rogue · Apr 13, 2013 at 11:36 PM 0
Share

You should have all your enemies(as well as many other things) saved as prefabs. Build your enemy in the scene(like you want it to start moving immediately) then drag it in the hierarchy in a folder in the Project pane. This will convert it to a prefab. You drag this into the enemy variable...

I'm going to have to stress that you may want to look a few tutorials before going headlong into a project. There is a lot of knowledge you'll need to know to make unity game. Although once you know what your doing Unity is the easiest thing out there :)

avatar image MrJesterXiii · Apr 13, 2013 at 11:46 PM 0
Share

Ah Awesome thanks, Yeah ive used Unity before to make a 2.5D platformer, but this is a much more complex idea. I never make it easy on myself lmao.

Thanks again buddy, ill try it out and come back with the results.

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

12 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

Related Questions

Enemy Spawning and Movement 0 Answers

How can i add simple back and forth movement on the Y-axis to an enemy that has velocity on the X-axis attached to it? 3 Answers

How to make an enemy stop and start movement in a tower defence game? 0 Answers

How to get a character to slowly move onto screen 1 Answer

Enemy fire rate? help! 2 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