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 BritishGuy · Jan 26, 2015 at 08:07 PM · physicsforcelocalshipaddforceatposition

AddForceAtPosition Locally Problem.

Hello.

I am trying to control a Rigidbody 0 gravity space ship with local thrusters for a full physics movement, I have read the docs and i seem to be doing everything right or so i think.

For my tests i have a cube for main body and 2 other cubes at the back "1 back left, 1 back right" what i am trying to achieve is when i press A (left engine) the ship turns right with force from that engine locally, D (right engine) turns the ship left with force from the right engine locally, but for some reason both of my engines no matter where i put them force the ship to start spinning clockwise, Any ideas where i went wrong? Thanks.

 #pragma strict
  var leftEngine : GameObject;
  var rightEngine : GameObject;
  var currentPosition1 : Vector3;
  var currentPosition2 : Vector3;
  public var speed : float;
  
  function Start () 
  {
      leftEngine = GameObject.Find("LeftEngine");
      rightEngine = GameObject.Find("RightEngine");
  }
  
  function Update () 
  {
      if(Input.GetKey(KeyCode.A))
      {
          currentPosition1 = leftEngine.transform.localPosition;
         rigidbody.AddForceAtPosition(Vector3.forward * speed, currentPosition1);
          
      }
      
      if(Input.GetKey(KeyCode.D))
      {
          currentPosition2 = rightEngine.transform.localPosition;
         rigidbody.AddForceAtPosition(Vector3.forward * speed, currentPosition2)
      }
  
  }

 Ship Structure:
      -Hull
        -leftEngine
        -rightEngine

 Design:
      [ ]   -hull
     [] []  -engines


Comment
Add comment · Show 4
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 BritishGuy · Jan 26, 2015 at 10:44 PM 0
Share

Been over it countless times, It is probably something so simple, But i am still learning. I am not looking for anyone to write me a new script, just a hint will go along way please. Thanks.

avatar image smoggach · Jan 26, 2015 at 10:55 PM 1
Share

Have you tried using Force$$anonymous$$ode.Impulse ? Use it as the third parameter in AddForceAtPosition

avatar image BritishGuy · Jan 26, 2015 at 11:03 PM 0
Share

Yes unfortunately that did not work, It is strange, the physics just want to keep rotating the ship clockwise no matter what i change or how i have the ship assembled.

avatar image SirAstral · Jan 27, 2015 at 02:52 AM 1
Share

You solved your own question then? Sounds good if so!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SirAstral · Jan 27, 2015 at 01:14 AM

sometimes odd things will happen with unity and physics. I have been playing with a few lately myself.

Verify all of the basics. Make sure that all of your geometries are squared... as in, make scale 1x1x1 and rotation of 0,0,0 for all of your objects on the ship. Verify that the drags on all rigid-bodies are matching perfectly. Are you using any Wind or other physics things that might push or pull on your ship?

If your engine cubes are children of the parent cube, you should make sure they are in positioned on each other perfectly before you add them together and move them, or move them to position first then add them to parent. I have had funny business happen myself, especially with transforms in relation to their parents if I move one around from parent to child making changes along the way.

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 BritishGuy · Jan 27, 2015 at 02:28 AM 0
Share

Thank you for the reply, I actually gave up on that approach and went with a modular approach. Each thruster now has its own "thrust" script then i am accessing them from within my ship controller, For now while testing the thrusters are only connected to the ship using "fixed joint"

The nice thing about using fixed joints is i can have engines / thrusters blown off ships which in turn will effect how they can manoeuvre.

The bad thing is they wobble all over the place like jelly :)

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Controller meets Rigidbody 1 Answer

add force to object that has 2 different rigid bodies 0 Answers

Ignore Force Imparted By Object 0 Answers

How to calculate force to apply to move object to a certain distance. 1 Answer

Model tips over for no reason 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