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
1
Question by mlkielb 1 · Sep 21, 2010 at 11:03 PM · instantiateraycasttransformdistance

Instantiate gameobject a certain distance away from transform

I'm thinking about the best ways to make a world war II style Anti Aircraft gun(with the puffs of black smokey explosives all around the target).

I was hoping it would be possible to first get the distance of the target with:

var distance = Vector3.Distance(transform.position, target.position);

And next instantiate an explosive gameObject at that distance with slight random rotations and distances applied. I'm not sure how to do this though.

If you can give me any tips for this method, or if you have another method that would be better to implement I would like to know.

Thanks in advance for any help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Billamu · Sep 22, 2010 at 12:10 AM

Here are some links that should help you out.

http://unity3d.com/support/documentation/Manual/Particle%20Systems.html

http://unity3d.com/support/documentation/ScriptReference/Random-rotation.html

http://unity3d.com/support/documentation/ScriptReference/Random-insideUnitCircle.html

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 mlkielb 1 · Sep 22, 2010 at 03:36 PM 0
Share

I've been using the insideUnitSphere since you mentioned the insideUnitCircle. This should do well for my AI ships. Thanks.

avatar image
2

Answer by runevision · Sep 22, 2010 at 08:41 AM

If you just want the puffs to appear at random positions around the target, then the position of the gun should be irrelevant. You can use Random.onUnitSphere to get a vector with a random direction.

This will set puffPosition to be at a random point 2 to 4 units away from the target position:

var puffPosition : Vector3 =
    target.position + Random.onUnitSphere * Random.Range(2.0, 4.0);
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 mlkielb 1 · Sep 22, 2010 at 03:37 PM 0
Share

Thanks for the response, I've been working with that function already. I just didn't get a chance to post a response yet.

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

No one has followed this question yet.

Related Questions

Position before the camera? 2 Answers

Help with moving instantiated object's transform 1 Answer

transform position and rotation of instantiated object 1 Answer

The Weirdest Bug Ever: GameObject Transform Appears in Editor to Be in One Spot but Instantiates and Registers in Another 2 Answers

[Closed] Instantiate wall/fence down a raycast from point A to point B? 0 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