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 p00ky · Apr 26, 2015 at 07:45 PM · addforceatposition

How exactly do you AddForceAtPosition with in LocalRotation?

Apologizes in advance from a noob :) I'm pretty new to Unity and coding in general and I'm having a few problems.

I have a flat-ish cube and I am trying to AddForceAtPosition in each corners transform.localRotation (Y axis) depending on gamepad input. However, the force is only ever applied in the Y axis of the world space (straight up).

I'm basically trying to make a Quadcopter. I'm sure there are easier ways of faking the same sort of movement but I'm more interested in the process of how the mixing of the motors works in real life.

Here's the code I made.....

 public Vector3 frontLeftRotor;  //location of Rotors
 public Vector3 frontRightRotor;
 public Vector3 rearLeftRotor;
 public Vector3 rearRightRotor;
 
 public float speed;   //Throttle Multiplier
 
 float currentThrottle = 0.0f;         //throttle
 float currentRotation = 0.0f;         //Rotation
 float currentForwardBias = 0.0f;      //forward lean
 
 void Update()
 {
 currentThrottle = state.ThumbSticks.Left.Y;            // Get Input (XinputDotNet)
 currentRotation = state.ThumbSticks.Left.X;
 currentForwardBias = state.ThumbSticks.Right.Y;
 
 Vector3 rotorLiftFrontLeft = new Vector3 (0, currentThrottle * speed, 0);    //Set Direction and Throttle
 Vector3 rotorLiftFrontRight = new Vector3 (0, currentThrottle * speed, 0);
 Vector3 rotorLiftRearLeft = new Vector3 (0, currentThrottle * speed, 0);
 Vector3 rotorLiftRearRight = new Vector3 (0, currentThrottle * speed, 0);
 
 
 player1.AddForceAtPosition(rotorLiftFrontLeft,(frontLeftRotor));       //AddForceAtPosition, this much force, at this position
 player1.AddForceAtPosition(rotorLiftFrontRight,(frontRightRotor));
 player1.AddForceAtPosition(rotorLiftRearLeft,(rearLeftRotor));
 player1.AddForceAtPosition(rotorLiftRearRight,(rearRightRotor));
 
 
 transform.localRotation *= Quaternion.Euler (currentForwardBias, currentRotation, 0);  //Only here for testing, adds lean to cube to test AddForceAtPosition direction
 
 }


Any help would be appreciated.

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

Answer by AlwaysSunny · Apr 26, 2015 at 07:44 PM

When you can, use empty child game objects to help with things like finding a specific point on a model. Place and name the child objects and let the script see them by exposing Transform variables. Your script can apply force at the position of the empties. Using extra helper empties can be very useful.

You should know that creating a good looking, good feeling, stable quad-copter simulation in pure PhysX is really not feasible. Not without extensive Vector Math, Physics, Unity, and PhysX experience. Even then you'd wind up taking such explicit control over what PhysX does, you might as well not use it (except for collision and simple motion). If you had the necessary experience to pull it off, you'd also know you'd be better served faking 90% of its dynamics.

When someone tried to tell me this years ago, I had to prove it to myself to believe it, so by all means, give it a shot. It will be very educational, but curb your expectations.

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 p00ky · Apr 26, 2015 at 07:58 PM 0
Share

Heh! Thanks for the heads up on the difficulty setting, it may be more than a little out of my league :) But I shall persevere for now & I shall certainly look into using empty gameobjects to begin with :)

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

Rigidbody2D AddForceAtPosition - adds more force the further away the target 1 Answer

AddForce to position on Rigidbody 2 Answers

Add Force based on Raycast 1 Answer

AddForceAtPosition Creating Torque When It Shouldn't 0 Answers

Add force on objects from a specific location in space 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