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 /
This question was closed May 24, 2013 at 10:18 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by Torca · May 23, 2013 at 11:41 PM · instantiateprefabs

instantiating a projectile continually over time

I have a prefab moving left to right across the screen I can get it to shoot at the player/camera on the z axis once at the start but I would like to have the enemy object keep shooting at the player as it moves across the screen. I have tried different things but I can't seem to get it to work. Any help would be great.

var projectile : Rigidbody; var initialSpeed = 20.0;

function Update() {

     {
     // create a new projectile, use the same position and rotation as the Launcher.
     var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
         
     // Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
     instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, initialSpeed, 0));

     // Ignore collisions between the missile and the character controller
     Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
     
 }

}

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 robertbu · May 24, 2013 at 12:16 AM 0
Share

Your question is unclear. It look like you will spawn a new projectile each frame, but you don't change where you aim the projectile. Is you question an ai$$anonymous$$g issue?

avatar image Fattie · May 24, 2013 at 10:17 AM 0
Share

as it turns out, you don't use instantiate during play in video games. you'll need to learn about pools

here is a long discussion

http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Benproductions1 · May 24, 2013 at 12:08 AM

Hello,

Since your question is so broad, I'll just give you a just as broad answer :)
One solution would be to make a timer, every time the timer reaches or goes below 0, you shoot and reset the timer. Thats it.

Hope this helps,
Benproductions1

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
1

Answer by FL · May 24, 2013 at 12:17 AM

Put instantiatedProjectile.LookAt(player) after the Instantiate.

I suggest you to put this code in the FixedUpdate() instead of Update() and use transform.LookAt(player) (for the enemy tranform) before the Instantiate.

Also, put a gap between the projectiles or they will collide with themselves.

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 Torca · May 24, 2013 at 02:16 AM 0
Share

Hi Guys

Thanks for the input. I played around a bit with your suggestions but keep getting errors. It's just over my head. Think I will just have to pay for some scripting.

Regards Thor

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Prefabs wont instantiate using a for loop? 1 Answer

instantiate prefabs/gameObjects 1 Answer

How to instantiate the prefabs on grid in Unity? 1 Answer

Instantiate Reference Problem 1 Answer

Dictionary Keys to Stack Enemy Types 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