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
0
Question by Heavy Wizardry · Dec 24, 2014 at 10:22 PM · rotationgameobjectphysics2d

Simulate rotation using two force thrusters

I'm currently working on a 2D space shooter game. I've decided to model everything using pure Newtonian mechanics. Is there a way to simulate rotation using two force thrusters?

What I do at the moment is I create a parent GameObject and put two thruster objects into it some distance apart of each other. I then apply force to those thrusters in hopes of moving the parent object, sadly nothing happens. What am I doing wrong?

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

Answer by EvilTak · Dec 25, 2014 at 12:54 PM

You can use Rigidbody2D.AddForceAtPosition. You can use a simple script as follows:

 public Transform leftThruster;
 public Transform rightThruster;
 public float force;
 
 void FixedUpdate(){
   Vector2 forward = new Vector2(transform.up.x, transform.up.y);
   //Thrusters
   Vector2 leftThrusterPos = new Vector2(leftThruster.position.x, leftThruster.position.y);
   rigidbody2d.AddForceAtPosition(force * forward, leftThrusterPos);
   //Same for rightThruster
 }

You can modify the code to add force only to one thruster to turn, i.e. when the left key is pressed, the right thruster will only provide the thrust and vice versa.

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 Heavy Wizardry · Dec 25, 2014 at 03:42 PM 0
Share

Thanks, it took me a while to figure it out for myself, but I finally did it using the method you've described (a more encapsulated version with a thruster object). :) I've checked back to add this as an answer, but you've already beaten me to it.

The parent will move the children relative to it, but the inverse of it is false. Would be nice if it could've been a built-in feature to enable such an option though.

Before I thought a joint might be a solution (sadly fixedJoined2D does not exist), but all I had to do was to read the API reference more closely.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Spawn GameObejcts random on an area without overlapping in 2d 1 Answer

Limit Rotation of physics object in 2D 1 Answer

How to get angular difference? 2 Answers

Camera rotation the same as player rotation 1 Answer

Limit gameobject rotation to -480 and 480 degrees? 2 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