Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 juanelo · May 21, 2011 at 08:24 PM · rigidbodyinstantiatevelocityprojectile

instantiate finding upstream velocity

How would you go about the following:

I have a rigidbody that is moving at variable speeds. The rigidbody has different children (non-rigidbodies), which in turn have more children, etc, etc,etc. At the end of the chain, One of these children is firing projectiles.

I´m firing these projectiles by instantiating them, and applying an initial velocity. I´ve figured that the way to get these to work properly is to add the velocity of the basic, moving rigidbody to the velocity of the projectile.

However, as I need this script to be generic, I would like to somehow find this velocity without resorting to utilizing gameObject.Find and querying the velocity of the rigidbody. Is there a more efficient way of going about this? Do the children of a rigidbody (even if they are not rigidbodies themselves) inherit the velocity in some query-able way?

Thanks!

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
Best Answer

Answer by Bunny83 · May 21, 2011 at 09:12 PM

All child object are even part of the rigidbody. I guess you have no other way than go the hierachy upwards and search your rigidbody. But you only have to do this once at start. You should save the reference in a variable.

JS or C#? it's always the same... (you should be forced to specify your prefered language when posting a question :D)

I guess you use JS?!?

So there are some different ways, but that depends on your setup. Normally rigidbodys should not be a child of something else because that would messup the physics. So to find the root GameObject of your sub-gameobject you can use Transform.root which returns the topmost gameObject in the chain.

 var ownerRigidbody : Rigidbody;
 function Start() {
     ownerRigidbody = transform.root.rigidbody;
 }
 
 function Update() {
     // use the velocity here: ownerRigidbody.velocity
 }

If you have your rigidbody as child object (maybe just for grouping) you could search the rigidbody by going the parent chain upwards:

 var ownerRigidbody : Rigidbody;
 function Start() {
     var current = transform;
     while (current != null && current.rigidbody == null) {
         current = current.parent;
     }
     if (current != null)
         ownerRigidbody = current.rigidbody;
 }

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 juanelo · May 23, 2011 at 11:05 PM 0
Share

Thank you, Bunny, transform.root was exactly what I needed

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiplying something.forward using a variable doesn't actually multiply, but multiplying by a number does. 1 Answer

Projectile launch insufficient velocity 2 Answers

Adding player velocity to projectile not working 0 Answers

Trouble with rb.Addforce(transform.foreward) 3 Answers

Controll 3D Rigidbody Projectile with Joystick 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