• 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 Roux69 · Aug 02, 2010 at 06:12 PM · projectileclones

how to differentiate clones?

Hi!

I want to have my character with the input of "fire1" to instantiate around 5 flying daggers gameobjects(prefab) around him and then give them a x velocity, but each at a different time.

so forgive me since it would make this 2 questions.

//Insantiate a rigidbody then set the velocity var projectile : Rigidbody; function Update () { // Ctrl was pressed, launch a projectile if (Input.GetButtonDown("Fire1")) { // Instantiate the projectile at the position and rotation of this transform var clone : Rigidbody; clone = Instantiate(projectile, transform.position, transform.rotation);

// Give the cloned object an initial velocity along the current // object's Z axis clone.velocity = transform.TransformDirection (Vector3.forward * 10); } }

This is the code I got from the script reference. The first question is: how can I loop the instantiate part of the code to create the 5 projectiles. The second question is: once the 5 daggers are created, how do I point to them individually?

Or would it be easier to have each of the projectiles their own script that sets their velocity?

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
2

Answer by 3dDude · Aug 02, 2010 at 06:25 PM

try this :

//Insantiate a rigidbody then set the velocity

var projectile : Rigidbody; var velocities : Vector3[];

function Update () {

// Ctrl was pressed, launch a projectile

 if (Input.GetButtonDown("Fire1")) {

 // Instantiate the projectile at the position and rotation of this transform
 for(i=0;i<velocities.length;i++){

 var clone : Rigidbody;

 clone = Instantiate(projectile, transform.position, transform.rotation);


 // Give the cloned object an initial velocity along the current 

 // object's Z axis
 clone.velocity = transform.TransformDirection (velocities[i]);
 }

}

}

so just fill out the array of velocity Vector3's and then it will clone as many as you say.

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 Roux69 · Aug 03, 2010 at 04:19 AM 0
Share

Firstly thank you for answering. There are a few things I don't understand though. Vector3 is supposed to be an array of 3 variables (x,y,z). what I don't understand is why you put vector3 in velocities and then call velocities.length (I most usuall used length to measure a string, not an array...)

And most probably this will then explain why when I put the 3 xyz in the [ ] at line 3 it give me an error: ; expected at end of line.

avatar image Roux69 · Aug 03, 2010 at 04:19 AM 0
Share

Also... as I see the script you've shown me it would create a projectile and then fire it in on loop pass. What I'm looking for is a loop that will create all, say, 5 projectiles, have them float in the air for a second and then fire them one at a time (like a magic spell). But at the moment, this way is fine... as long as I get to have a few nifty projectiles flying in the right direction. (oh and sorry for not mentioning that before, but I'm making(trying to) a 2d scroller castlevania clone)

Thank you for the time you put in helping me figure this out.

avatar image 3dDude · Aug 03, 2010 at 01:41 PM 0
Share

so.. does it work know? i'm not clear on that :)

avatar image Roux69 · Aug 03, 2010 at 04:03 PM 0
Share

no it doesn't work... like I said in my first comment, it gives me an error at line 3 ; expected at end of line

avatar image john 2 · Aug 20, 2010 at 06:24 PM 0
Share

lfhkdjshjfashjdksfhjlkdfdhhfjdkhjfdshjlkfdhhfakdh

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Arcing projectile using physics 0 Answers

Projectile Hit Detection with Bullet Drop 1 Answer

How to use RaycastHit2D for a 2D projectile? 2 Answers

How to instantiate a projectile only from the weapon prefab of the firing player? 1 Answer

Projectiles shoot in time with Update() function, instead of intended firing rate in coroutine. 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