Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by DoubleUU · Feb 22 at 03:33 AM · 3daddrelativeforce

AddRelativeForce Using Rotating Engine

I'm trying to create a ship that is propelled by an engine that rotates thrust around it in a circle while the ship itself remains fixed. It is a side scrolling flying game, so the ship moves up and down along the Z axis only.

I've created this hierarchy:

  Player <- Has Rigidbody and movement script
   Ship <- Doesn't rotate but flies around
    Engine Mount <- Rotates to direct thrust
     Engine Mesh
      Particle System

The ship is a simple sphere and the engine rotates around the outside around the X axis to push along the Z axis.

I have the player oriented so that Z is forward (Y=90) and all the objects below are rotated 0 on all axis. I'm familiar with using AddRelativeForce() when the Rigidbody is controlling the vector but I can't seem to get this to work. I've tried using the Engine Mount's transform.forward but that doesn't work at all. It seems to just push one direction no matter how it is rotated.

All I want to do is apply a thrust force along the same axis as the Z axis of the engine mount. I can see that when I rotate the engine mount during game play that the Z axis is changing but the applied force direction doesn't seem to change, or at least isn't changing as expected. It never seems pointing in the same direction as the Z axis.

I tried to find the math to just grab the Z axis from the engine mount transform and use that to calculate the vector3 but I haven't had any luck. Any help would be appreciated. I've tried all sorts of orientation changes to flip around the engine mount but nothing has worked.

I'm sure that I'm missing something silly.

Comment
Add comment · Show 1
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 DoubleUU · Feb 22 at 04:43 AM 0
Share

I got this to work, but I don't like it. Seems overly complicated.

 public class ShipMover : MonoBehaviour {
 
     [SerializeField] GameObject engineMount = default;
 
     Rigidbody rb = default;
 
     void Start() {
         rb = GetComponent<Rigidbody>();
     }
 
 
     void Update() {
 
         if (Input.GetKey(KeyCode.W)) {
             Vector3 wrong = engineMount.transform.forward;
             Vector3 correct = new Vector3(wrong.z, wrong.x, -wrong.y);
             rb.AddRelativeForce(correct);
 
         }
 
         if(Input.GetKey(KeyCode.A)) {
             engineMount.transform.Rotate(Vector3.left);
         }
         if (Input.GetKey(KeyCode.D)) {
             engineMount.transform.Rotate(Vector3.right);
         }
     }
 }

0 Replies

· Add your reply
  • Sort: 

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

216 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 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 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 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 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 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 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 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 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 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

What is the best method of creating an element in a 3D environment along a specific axis? 0 Answers

Quaternion Roation Mouse Script 0 Answers

Cinemachine (or the unity compiler) broken due to some unknown reason 1 Answer

How important is the order of Vertices in the mesh array that the triangles point to? 0 Answers

some textures are invisible 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