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 CyanCorsair · Nov 04, 2014 at 09:49 AM · physicsrigidbodyspaceshipthrust

Composite body physics

I have a spaceship that is supposed to have a total of 12 thrusters, which are intended to move the ship, each providing thrust in a specific direction.

Can I simply use a parent-child relationship, with the parent being a rigidbody - the ship - (the thrusters are not rigidbodies), so that the thrusters would control the parent ships movement? Or do I need to use fixed joints?

How would I go about setting up a configuration like this in Unity?

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 Kiwasi · Nov 04, 2014 at 07:21 PM 1
Share

To clarify you can't use the parent child relationship with rigid bodies. Rigid bodies need to be constrained via joints. To see why simply try it.

avatar image CyanCorsair · Nov 07, 2014 at 08:17 AM 0
Share

I see. To make a joint - since I'm making my models in Blender, can I just make a single bone armature and then use that as an attachment point in Unity? Or do I have to attach the thruster to it in Blender?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AlwaysSunny · Nov 04, 2014 at 09:49 AM

It sounds like a "thruster" is an arbitrary point + direction in relation to the model. In that case, for "true" thruster physics, you'd simply AddForceAtPosition() given the thruster's relative position, direction, and scalar force.

Note this may not give the intended results. For an "intuitive" thruster system, you'll have to deterministically assign the appropriate force from each thruster based on input. Or, better yet, drive the rigidbody motion from a single calls to AddTorque() or AddForce(), and visually show the thrusters working through particle effects or what-have-you. Using the later method, you could still perform the deterministic calculations to control the intensity of the "active thruster" effect.

Comment
Add comment · Show 4 · 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 CyanCorsair · Nov 04, 2014 at 07:05 PM 0
Share

I think the first option sounds more like what I'm intending to achieve, although I'll need to experiment. I should also clarify what I want the thruster to be, exactly - initially I thought it should be a rigid body with their own mass, too, as the ship isn't causing the acceleration since the thrusters are, thereby getting around the "don't make parent-child rigid body relationships" I saw mentioned in another thread.

So if I were to use this system, I would have to look for key/mouse input, and then run the function in the Thruster class to get the thrust amount, and then use AddForceAtPosition() on the ships script?

avatar image AlwaysSunny · Nov 04, 2014 at 07:49 PM 1
Share

That should work in principle, but it gets confusing pretty fast. Consider:

For lateral motion, the appropriate amount of force from each thruster can be found by comparing the dot product of the thruster direction and desired direction of lateral motion. Note that for this to "work right" - meaning it feels intuitive and doesn't create unwanted rotational acceleration - your thrusters must somehow incorporate their relative positions in their calculations (I'm not sure how to go about this myself without breaking out my physics textbooks).

Also consider, to use this same thruster system to drive rotational motion, the rotation input must be considered in a similar but separate way. Each thruster would need to compare its direction-of-force against the object's CoG, and find the appropriate force based on how well its participation would yield the correct rotational acceleration. (I'm not totally sure how to approach that, either).

Frankly, unless you're making a game for actual rocket scientists - or you have one on retainer to help build all your vehicles - the single-call system will save you a lot of headaches. To the untrained eye, the thrusters will appear to actually work and drive motion, when in fact they're merely decorative. You still have to do all the above calculations to ensure their visual effects fire with appropriate intensity, but the physics simulation itself will be separate, and therefore much more simple, stable, and intuitive to program and control.

Also consider - with the single-call system, you could eschew nearly ALL of these intensive physics calculations by simply using an "accumulation" effect, where the intensity of your thrusters' visual effects are simply driven by lateral and rotational velocity. This is how I'd approach the problem, if at all possible.

avatar image Kiwasi · Nov 04, 2014 at 09:55 PM 1
Share

$$anonymous$$erball seems to be doing pretty well with rocket scientists :)

As pointed out faking it is definitely easier. Unless thrust control is a critical part of your gameplay I wouldn't bother doing it properly.

avatar image CyanCorsair · Nov 05, 2014 at 09:39 AM 0
Share

I see. The physics involved in that sound a bit above me currently, so the single call system looks to be my best bet, then. And in that situation I could have the "moving thrusters" actually just be a particle effect source rather than a fully modeled element on the ship...that does decrease the complexity of ship design, since the thrusters' locations don't need to be 100% mathematically correct either.

Thank you.

avatar image
1

Answer by Habitablaba · Nov 04, 2014 at 09:23 PM

I've implemented a similar design both ways (children and joints), and both worked well for me.

In the case of the parent/child relationship, my thrusters had a script which had a configurable 'thrust normal' to determine which direction the thrust would act, along with a reference to the parent rigidbody (so I didn't have to find it each frame). Then, still in the thruster script, I calculated the amount of thrust I expected that engine to produce. This was based on things like throttle, fuel level, etc.
Finally, in the FixedUpdate for the thruster, I used:

 this.parentRigidbody.AddForceAtPosition(this.thrustNormal * this.forceMagnitude, this.transform.position);

Using configurable joints was arguable easier for scripting, since you don't have to worry about the parent rigidbody, you can just use your own.
For large ships with lots of thrusters, it is/was a pain to set up all the joints properly.

If I had it all to do again... I think I would have stuck with the parent/child relationship (and in fact, may end up going back after all).

Comment
Add comment · Show 2 · 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 CyanCorsair · Nov 05, 2014 at 09:42 AM 0
Share

Then it looks like child/parent relationships will be the way to go, although I'll (as commented above) make my thrusters just particle effect sources; still, it's useful knowledge to have. Do you have a video demo of what you were working on, by the way? Just so I could see it in action.

avatar image Habitablaba · Nov 05, 2014 at 06:07 PM 0
Share

I do not, currently. It is in such a 'quick and dirty' phase that any attempt at a demo would no doubt be plagued by any number of other demons currently haunting the project, and nobody wants to see that.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I keep rigid bodies from sliding when applying fake gravity based on moving parent? 1 Answer

How should I structure an object with a mix of rigidbody and non rigidbody children? 1 Answer

Does setting the rotation of an object override the physics engine? 1 Answer

Stop rigidbody A from applying physics to rigidbody B while still allowing collisions between the 2 objects 0 Answers

OnCollisionEnter isn't working between two RigidBodies 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